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

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Cross table with 2 data columns

Hi Experts,


I need your help with the below situation.


I have the below table in the DB:

InvoiceCustomer CodeItemQty 1Qty 2Qty 3Supplied 1Supplied 2Supplied 3
11004699895221000
11004545927992010
22006998259969123

I want to get a table that holds the data in a way that each type of qty will be side by side.

i.e. in the First line Qty 1 and Supplied 1 are the same type of qty so they will be called type 1.

the Qty will be 2 and the Qty supplied will be 0 (please look on the 1st row in the table below)


Please note that i have to do it my script.


The final result should look like the below:

InvoiceCustomer CodeItemTypeQtyQty Supplied
11004699895120
11004699895220
11004699895310
11004545927190
11004545927291
11004545927320
22006998259191
22006998259262
22006998259393

Thanks

2 Replies
sunny_talwar

Try this


Table:

CrossTable(Field, Value, 3)

LOAD * INLINE [

    Invoice, Customer Code, Item, Qty 1, Qty 2, Qty 3, Supplied 1, Supplied 2, Supplied 3

    1, 100, 4699895, 2, 2, 1, 0, 0, 0

    1, 100, 4545927, 9, 9, 2, 0, 1, 0

    2, 200, 6998259, 9, 6, 9, 1, 2, 3

];


TempTable:

LOAD Invoice,

[Customer Code],

Item,

Field,

Value,

SubField(Field, ' ', 2) as Type

Resident Table;


DROP Table Table;


FinalTable:

LOAD Invoice,

[Customer Code],

Item,

Type,

Value as Qty

Resident TempTable

Where WildMatch(Field, 'Qty*');


Left Join (FinalTable)

LOAD Invoice,

[Customer Code],

Item,

Type,

Value as [Qty Supplied]

Resident TempTable

Where WildMatch(Field, 'Supplied*');


DROP Table TempTable;

marcelviegas
Creator II
Creator II

hi Roei Benishti,

follows qvw attached:


temp:

LOAD Invoice, [Customer Code], Item, [Qty 1], [Qty 2], [Qty 3], [Supplied 1], [Supplied 2],

     [Supplied 3]

FROM (ooxml, embedded labels, table is Plan1);

NoConcatenate

table_result:

load Invoice,[Customer Code],Item,num(1) as type,sum([Qty 1]) as qty, sum ([Supplied 1]) as [Qty Supplied]

Resident temp

group by Invoice,[Customer Code],Item;

Concatenate

load Invoice,[Customer Code],Item,num(2) as type,sum([Qty 2]) as qty, sum ([Supplied 2]) as [Qty Supplied]

Resident temp

group by Invoice,[Customer Code],Item;

Concatenate

load Invoice,[Customer Code],Item,num(3) as type,sum([Qty 3]) as qty, sum ([Supplied 3]) as [Qty Supplied]

Resident temp

group by Invoice,[Customer Code],Item;

drop table temp;