Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
MT4T
Creator
Creator

Proportional calculation

Hey,

I have issues with this structure of data. I need split values Using Qlik sense script.

Logic behind data is:

I have Number of pallets (places within truck). But it has summarized value only (FINV_Real_Value) only in rows with number of pallets. All rows below with 0 belong to the same value.

So, my calculation should be I pick total value for 9 pallets - 1411 EUR (second row) and i need divide this with number of rows (2) which are belong to same FINV_Real_Value (in 4th row start new position). And split this value into each record proportionally. Expected result is visible in column "NEED THIS"/

MT4T_1-1700041556737.png

 

Labels (2)
1 Solution

Accepted Solutions
vincent_ardiet_
Specialist
Specialist

Ok, so there is no unique key per rows to be grouped, right?
If this is the case, you can add those 3 fields in your loading script:

If(Number_Of_Pallets=0,Peek(Previous_Number_Of_Pallets),Number_Of_Pallets) as Previous_Number_Of_Pallets,
If(FINV_Real_Value=0,Peek(Previous_FINV_Real_Value),FINV_Real_Value) as Previous_FINV_Real_Value,
If(Number_Of_Pallets=0,Peek(Previous_FINV_Real_Value)/Peek(Previous_Number_Of_Pallets),FINV_Real_Value/Number_Of_Pallets) as Value_Per_Pallet

 

 

View solution in original post

3 Replies
vincent_ardiet_
Specialist
Specialist

If you don't have a unique key to identify which rows are together, this is a bit tricky.
Are you sorting those data or are they coming from your source already sorted?
Have you access to the loading script?

MT4T
Creator
Creator
Author

Hey, unique key with order should be " Loading_Detail_ID ", My source data are sorted according to this col.

Sample data are available within the uploaded app. 

vincent_ardiet_
Specialist
Specialist

Ok, so there is no unique key per rows to be grouped, right?
If this is the case, you can add those 3 fields in your loading script:

If(Number_Of_Pallets=0,Peek(Previous_Number_Of_Pallets),Number_Of_Pallets) as Previous_Number_Of_Pallets,
If(FINV_Real_Value=0,Peek(Previous_FINV_Real_Value),FINV_Real_Value) as Previous_FINV_Real_Value,
If(Number_Of_Pallets=0,Peek(Previous_FINV_Real_Value)/Peek(Previous_Number_Of_Pallets),FINV_Real_Value/Number_Of_Pallets) as Value_Per_Pallet