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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How do I convert columns of data into rows - using QV Script

Hi,

I have a large 'fixed length' data file (TXT) that I am bringing into Qlikview.  I am using the script to split out and label each field and that has worked well so far.

The data captures 100 possible procedure codes and 100 possible diagnosis codes (yes, the application is health).

I have to scan along these codes looking for certain matches, then apply a label to this patient's record accordingly.   I believe this would be easier to do if the procedure and diagnosis codes were in their own table with a row for each one and a primary key linking back to the main patient record.

See below an example of the data as it currently resides in QV.

PrimaryKeyProcCode 1ProcCode 2ProcCode 3ProcCode 4ProcCode 5ProcCode 6ProcCode 7ProcCode 8ProcCode 9DiagCode 1DiagCode 2DiagCode 3DiagCode 4DiagCode 5DiagCode 6DiagCode 7DiagCode 8DiagCode 9
100112341819-0030473-0041801-00                                                2K22.22B37.811S27.831Y84.81Y92.22                               
100112436812-0011900-00                                                        2C612M8010/32C79.52M8010/62N32.8                               
100112590466-0190481-00                                                        2O70.01O71.822Z37.02Z72.0                                       
1001126                                                                        2J44.1                                                               
1001127                                                                        2S32.832T08.02X592Y92.92U73.92J44.9                       


Say I am asked to identify where a patient has had a procedure of Adnoidectomy (41801-00).  I have to build some sort of MATCH to identify and label this patient as Adnoidectomy.  But I also have to check for numerous other procedure codes - just a select list.  Now my MATCH will have to be nested into IF statements so that I end up with one new field that states what this patient had.

I think this these fields could be better tested if they ran down the page.  ie:

PrimaryKeyCodevalue
1001123ProcCode 141819-00
1001124ProcCode 136812-00
1001125ProcCode 190466-01
1001123ProcCode 230473-00
1001124ProcCode 211900-00
1001125ProcCode 290481-00
1001123ProcCode 392515-29

What are your thoughts?

Can I pivot the data from a row to a column and then test it for a result?  Once I've used the pivoted data I can drop it.

Or should I build a dirty great big nested MATCH statement and then test 100 columns of procedures and 100 columns of diagnosis codes?

Regards,

John.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I think it could look exactely like this as a line in your script:

Crosstable (Code, Value) Load * resident Yourtable;

Crosstable is a load prefix (like join etc.), it specifies a certain way to load the data.

If your Yourtable field structure looks like

primarykey,procedure1,procedure2,procedure3.....

it should work just fine. Just give it a try.

edit:

You could also create an excel with some line of your data, then use the table wizard (enter transformations -> Crosstable ) to play around and get familiar with the syntax.

edit2:

Or try this in a new script:

Crosstable (Code, Value) LOAD *

INLINE [

Key, Code1, Code2, Code3

1, a, x, a1

2, b, y, a2

3,c, z, a3

4,d, x, a4

5,e, z, a5

];

View solution in original post

6 Replies
swuehl
MVP
MVP

John,

I think what you need here is a CROSSTABLE LOAD. Please check the Manual for details.

I believe it will probably look like

Crosstable (Code, Value) LOAD * resident Yourtable;

Hope this helps,

Stefan

Anonymous
Not applicable
Author

Hi Stefan,

I have looked at the syntax for this command but am not sure how it would work.

For example: each row has primarykey,procedure1,procedure2,procedure3.....

How exactly would the CROSSTABLE Load look?

The Load Resident part is fine.

Regards,

John.

disqr_rm
Partner - Specialist III
Partner - Specialist III

Try this:

CrossTable(Code, Value)

LOAD PrimaryKey,

     [ProcCode 1],

     [ProcCode 2],

     [ProcCode 3],

     [ProcCode 4],

     [ProcCode 5],

     [ProcCode 6],

     [ProcCode 7],

     [ProcCode 8],

     [ProcCode 9],

     [DiagCode 1],

     [DiagCode 2],

     [DiagCode 3],

     [DiagCode 4],

     [DiagCode 5],

     [DiagCode 6],

     [DiagCode 7],

     [DiagCode 8],

     [DiagCode 9]

FROM

C:\Users\admin\Desktop\Book1.xlsx

(ooxml, embedded labels, table is Sheet1);

swuehl
MVP
MVP

I think it could look exactely like this as a line in your script:

Crosstable (Code, Value) Load * resident Yourtable;

Crosstable is a load prefix (like join etc.), it specifies a certain way to load the data.

If your Yourtable field structure looks like

primarykey,procedure1,procedure2,procedure3.....

it should work just fine. Just give it a try.

edit:

You could also create an excel with some line of your data, then use the table wizard (enter transformations -> Crosstable ) to play around and get familiar with the syntax.

edit2:

Or try this in a new script:

Crosstable (Code, Value) LOAD *

INLINE [

Key, Code1, Code2, Code3

1, a, x, a1

2, b, y, a2

3,c, z, a3

4,d, x, a4

5,e, z, a5

];

Anonymous
Not applicable
Author

Ah, it does work!

I just need to make sure I have my primarykey as field number 1 then away it goes.

Brilliant!

Anonymous
Not applicable
Author

both answers are correct.

thank you Gentlemen.