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

Get if sum conditions

I have load script that load data from database. I need to get new column for table that has value based on following condition.As an example in attach image, for the row that with PRIORITY_CATEGORY 33 I need to get new column that has  sum of qty_remaining below the value of PRIORITY_CATEGORY. for PRIORITY_CATEGORY 33 i need to get new column with value 0.00048

Labels (8)
1 Solution

Accepted Solutions
Kushal_Chawda

@layanmahendra  try below expression

 

=sum(aggr(rangesum(above(total sum(QTY),1,RowNo())), RPART, (PRIORITY_CAT,(NUMERIC,ASCENDING))))

 

LOAD *
Inline [
RPART,QTY, PRIORITY_CAT
A,10,10
A,15,5
A,20,10
A,5,33
A,3,4

B,10,7
B,5,6
B,5,5
]
;

Screenshot 2023-05-30 at 11.30.35.png

 

View solution in original post

5 Replies
Kushal_Chawda

@layanmahendra  Is this logic required only for category 33? I can see there is another category with required value but what if there more than one category ? which value need to pick?

layanmahendra
Contributor
Contributor
Author

Yes there are 
I think this attachment in more details what i need to be figure 

Kushal_Chawda

@layanmahendra  try below expression

 

=sum(aggr(rangesum(above(total sum(QTY),1,RowNo())), RPART, (PRIORITY_CAT,(NUMERIC,ASCENDING))))

 

LOAD *
Inline [
RPART,QTY, PRIORITY_CAT
A,10,10
A,15,5
A,20,10
A,5,33
A,3,4

B,10,7
B,5,6
B,5,5
]
;

Screenshot 2023-05-30 at 11.30.35.png

 

layanmahendra
Contributor
Contributor
Author

Thank you this is do the work. But I need to do it for combined with another column YEAR. like this,

LOAD *
Inline [
RPART,QTY, PRIORITY_CAT,YEAR
A,10,10,2022
A,15,5,2023
A,20,10,2023
A,5,33,2022
A,3,4,2022

]

output should be 

RPART                      QTY             PRIORITY_CAT                   YEAR                  RESULT_QTY

A                                   10                     10                                        2022                         3

A                                    15                     5                                          2023                         18

A                                    20                     10                                       2023                           23    

A                                      5                       33                                      2023                         48

A                                    3                          4                                        2022                           3

 

Please how to do such??

 

Thank you

 

layanmahendra
Contributor
Contributor
Author

@Kushal_Chawda 

Thank you and this is working. But now i need to get result based on YEAR as well.
output should be like this