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

Show only sum of values for a dimension if sum is above limit based on other dimension

Hi,

I need to show the sum of a value over a dimension but only if the sum of those values are above a limit over some other dimensions.

Lets say I have this example data:

row
monthversionnetworktotal_amountsub_amount
191a94
292a304
3101a457
4102a509
5103a105
6102b508
7113a209
8114a154
9114b10010
10115b402
11125a709
12126b108
13127b709

I only want to use the total_amount and sub_amount if the sum of total_amount for the month and network is above a certain limit, lets say 40. Then I want to show the sum of the included values in a new table where I only have the month as dimension.

In this example it should be as follows:

Row 1 and 2: Should not be included in the calc since 39 (9+30) is below 40.

Row 3, 4, 5: Should be included in the calc since 105 (45+50+10) is above 40.

Row 6: Should be included in the calc since 50 is above 40.

Row 7, 8: Should not be included in the calc since 35 (20+15) is below 40.

Row 9, 10: Should be included since 140 (100+40) is above 40.

Row 11: Should be included since 70 is above 40.

Row 12, 13: Should be included since 80 (10+70) is above 40.

The result table shall look like this:

month
sum(total_amount)
sum(sub_amount)
10155 (sum of rows 3, 4 ,5 ,6)29
11140 (sum of rows 9, 10 since 7 and 8 shall be excluded)12
12150 (sum of rows 11, 12, 13)26

The closest I have come up with is to set month as dimension and the following as expressions:

sum({<total_amount={"=aggr(sum(total_amount), month, network)>=40"}>} aggr(sum(total_amount), month, network))

sum({<total_amount={"=aggr(sum(total_amount), month, network)>=40"}>} aggr(sum(sub_amount), month, network))

However, as those expessions seem to give the correct result in this small example it will not give the correct result always. In my real data it will present some month as "-".

Any suggestions?

1 Solution

Accepted Solutions
antoniotiman
Master III
Master III

Try this

Dimension : month

Expressions :

Sum(Aggr(If(Sum(total_amount) > 40,Sum(total_amount)),month,network))

Sum(Aggr(If(Sum(total_amount) > 40,Sum(sub_amount)),month,network))

View solution in original post

2 Replies
antoniotiman
Master III
Master III

Try this

Dimension : month

Expressions :

Sum(Aggr(If(Sum(total_amount) > 40,Sum(total_amount)),month,network))

Sum(Aggr(If(Sum(total_amount) > 40,Sum(sub_amount)),month,network))

Anonymous
Not applicable
Author

Thank you Antonio,

It seems to work perfect