Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to convert the data format

I try to convert the data into a different structure when loading the data. Here is the old data format I have:

  [raw data]

Customer IDCategoryBrandImage1Image2RankCopy
111MilkabcStrongly DisagreeAgreeJ2Neutral
112MilkabcNeutralDisagreeJ3Strongly Disagree
113MilkabcDisagreeNeutralJ2Neutral
114MilkabcStrongly AgreeStrongly DisagreeJ4Neutral

The expected data structure would be:

 

Customer IDCategoryBrandQuestionAnswer
111MilkabcImage1Strongly Disagree
112MilkabcImage1Neutral
113MilkabcImage1Disagree
114MilkabcImage1Strongly Agree
111MilkabcImage2Agree
112MilkabcImage2Disagree
113MilkabcImage2Neutral
114MilkabcImage2Strongly Disagree
111MilkabcRankJ2
112MilkabcRankJ3
113MilkabcRankJ2
114MilkabcRankJ4
111MilkabcCopyNeutral
112MilkabcCopyStrongly Disagree
113MilkabcCopyNeutral
114MilkabcCopy

Neutral

Since # of column is flexible, so I use for.. next to load. it should be something like:

For i = 1 to NoOfFields([raw data])-4

Concatenate

[temp]:

LOAD

[Customer ID] as CID,

Category as Category,

Brand as Brand,

FieldName(i+4,[raw data]) as Question;

Next i

But this does not work. Can someone tells me what's wrong with this code? I am new to Qlikview, so not sure if my code is correct or not in Qlikview.

1 Solution

Accepted Solutions
3 Replies
swuehl
MVP
MVP

Have a look at

The Crosstable Load

Not applicable
Author

Thanks for sharing this. It's helpful for a given table.

But if I have undefined # of fields and the field name is also different for each table. Is there a way to create a loop to crosstable dynamically.

For example, I will do 3 fields in this table, but in next table I need to do 9 fields. If I can have a code and do not need to change for each table when doing this data transfer.

Thanks

swuehl
MVP
MVP

Maybe something like

CROSSTABLE (Question, Answer, 3)

LOAD * FROM ....;