Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

How would I make the first row of a loaded table to be used as the fields' names?

Hi,

Pretty much, as it says in the topic, how would I use the first row as the fields' names for that table?

Here's an example of what I mean:

LOAD * INLINE [

    @1, @2, @3, @4

    Product, Jan, Feb, Mar

    p1, 10, 20, 30

    p2, 11, 21, 31

    p3, 12, 22, 32

];

What I need to get out of this is:

Product | Jan | Feb | Mar

-----------------------------

p1         | 10   | 20   | 30

p2         | 11   | 21   | 31

p3         | 12   | 22   | 32

One of the ways I can think of is to STORE the table as a CVS and then re-load it as a new table with embedded headers, but that's not very elegant as this portion is in a nested loop.

Thanks,

Siarhei K.

1 Solution

Accepted Solutions
isaiah82
Contributor III

How would I make the first row of a loaded table to be used as the fields' names?

Use the peek function to get the values and rename statement to change the field names.  Use a for loop to cycle through each field with NoOfFields function value to determine the number of iterations.  I do stuff like this sometimes for crazy purposes.

Then you'll (obviously) want to remove the 1st row from the table.  Last I checked QV doesn't have a glamorous way to do this (like an SQL DELETE statement.)  You can accomplish this a few different ways; post back if you need help.

4 Replies
isaiah82
Contributor III

How would I make the first row of a loaded table to be used as the fields' names?

If I read this correctly all you need to do is just delete the @1, @2...row in your inline statement.  When using inline the first row is used as field names.

Not applicable

How would I make the first row of a loaded table to be used as the fields' names?

Yes, i get that, but this was just an example.

Imagine that I already have a table (loaded from somewhere and processed a zillion times) where the field names are useless to me, since the first row contains the information that I would like to use as the new fields' names for that same table.

isaiah82
Contributor III

How would I make the first row of a loaded table to be used as the fields' names?

Use the peek function to get the values and rename statement to change the field names.  Use a for loop to cycle through each field with NoOfFields function value to determine the number of iterations.  I do stuff like this sometimes for crazy purposes.

Then you'll (obviously) want to remove the 1st row from the table.  Last I checked QV doesn't have a glamorous way to do this (like an SQL DELETE statement.)  You can accomplish this a few different ways; post back if you need help.

Not applicable

How would I make the first row of a loaded table to be used as the fields' names?

Wow, you're on a roll!

Thanks again.