Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

QV Union from one table

I have a table that I need to reorganise a bit in the Load Script to make rows out of data in separate columns.

For instance:

DateCode1Time1Reason1Code2Time2Reason2Code3Time3Reason3
1/11/15ABC34Test1DEF23Test2
2/6/15DEF5Test3
31/7/15GHI12Test4JKL3Test5ABC30Test6
8/2/16MNO9Test7
15/8/16DEF3Test8ABC106Test9

And what I need is:

DateCodeTimeReason
1/11/15ABC34Test1
1/11/15DEF23Test2
2/6/15DEF5Test3
31/7/15GHI12Test4
31/7/15JKL3Test5
31/7/15ABC30Test6
8/2/16MNO9Test7
15/8/16DEF3Test8
15/8/16ABC106Test9

The entire table is already loaded (with lots of other information) but I need to be able to do some analysis on the codes individually.

This should be really simple, but I just can't see it.

3 Replies
sunny_talwar

I think what you need here is The Crosstable Load

tracysmart
Creator II
Creator II

You might want to look at the Crosstable load and pivot these columns around in the script.

Other options would be to rebuild the table using resident loads and create 3 columns for Code, Time and reason . The trouble here is you will also be repeating all the other columns in the table 3 times and this could give you incorrect results as granularity of data has changed.

You could build a table to the side of the main table linking on just date and have 3 new columns Code, Time and reason in here. This wont affect the granularity of the data but you are adding an extra join and extra data.


NewTable:
LOAD
DATE,
CODE1 AS Code,
Time1 AS Time,
Reason1 AS Reason
Resident MyTable;
concatenate
LOAD
DATE,
CODE2 AS Code,
Time2 AS Time,
Reason2 AS Reason
Resident MyTable;
concatenate
LOAD
DATE,
CODE3 AS Code,
Time3 AS Time,
Reason3 AS Reason
Resident MyTable;

Anonymous
Not applicable
Author

Think I've got it. What I ended up doing is 3 Unions on the same table to load the date, code, mins, and reason.

CrossTable looked promising, but didn't seem to handle the four output columns unless I'm missing something.