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: 
maepana
Contributor
Contributor

Load script: How to rearrange and group header and line items

Hi experts,

Could you advice, how to right load script for below case. I have tried but failed...

Source data:

Header

LineitemUp or DownPrice
100AAAU$20
100BBBD$20
200AAAU$30
200BBBD$30
300CCCU$10
300DDDD$5
300AAAD$5

 

Output1:

Grouping based on [Up or Down] and [Lineitem] pattern of [Header], sum by [Price]

Shape No.Up lineitemDown lineitemTotal Up PriceTotal Down Price 
1AAABBB5050<- Summarized header 100 and 200 info
2CCCDDD,AAA1010<- Summarized header 300 info

 

Output2:

Link table of [Header] and [Shapre No.]

HeaderShape No.
1001
2001
3002

 

Not sure  if this is possible in Qlikview...

Labels (7)
6 Replies
Taoufiq_Zarra

what I didn't get , how you group DDD,AAA ?

2CCCDDD,AAA1010<- Summarized header 300 info
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Kushal_Chawda

How do you define shape no? Seems confusing. Can you elaborate?

Taoufiq_Zarra

If I understood correctly, you need this :

 

Data:

LOAD if(Header=300,2,if(Header=200 or Header=100,1)) as [Shape No.],if([Up or Down]='D',Lineitem) as [Down lineitem],if([Up or Down]='U',Lineitem) as [Up lineitem],
if([Up or Down]='D',Price) as [Total Down Price],if([Up or Down]='U',Price) as [Total Up Price],

* INLINE [
    Header, Lineitem, Up or Down, Price
    100, AAA, U, 20
    100, BBB, D, 20
    200, AAA, U, 30
    200, BBB, D, 30
    300, CCC, U, 10
    300, DDD, D, 5
    300, AAA, D, 5
];


output2:

load distinct Header,[Shape No.] resident Data;

output1:

load [Shape No.],concat(distinct [Up lineitem],',') as [Up lineitem],concat(distinct [Down lineitem],',') as [Down lineitem],
sum([Total Up Price]) as [Total Up Price], sum([Total Down Price]) as [Total Down Price]
 resident Data group by [Shape No.];


drop table Data;

 

output :

Capture.PNG

 

output1:

Capture.PNG

 

output2:

 

Capture.PNG

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Saravanan_Desingh

One solution is.

tab1:
LOAD * INLINE [
    Header, Lineitem, Up or Down, Price
    100, AAA, U, 20
    100, BBB, D, 20
    200, AAA, U, 30
    200, BBB, D, 30
    300, CCC, U, 10
    300, DDD, D, 5
    300, AAA, D, 5
];

Left Join(tab1)
LOAD Header, Concat(Lineitem,'',[Up or Down]='U') As Pattern
Resident tab1
Group By Header
;

Left Join(tab1)
LOAD *, AutoNumber(Pattern) As [Shape No.]
Resident tab1;
Saravanan_Desingh

Output:

commQV38.PNG

Brett_Bleess
Former Employee
Former Employee

You have received multiple posts to your thread, we would greatly appreciate it if you would return to the thread and close it out by using the Accept as Solution button on the post(s) that helped, as this gives the poster(s) credit for the help and lets other Members know what worked.  If you did something different, you can post what you did and then mark that, but if any of the other posts gave you ideas, I would use the Like indicator on those posts to give them some credit for the help too, and if you have further questions, please leave an update post.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.