Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
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
Creator III
Creator III

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.

View solution in original post

4 Replies
isaiah82
Creator III
Creator III

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
Author

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
Creator III
Creator III

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
Author

Wow, you're on a roll!

Thanks again.