Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
kennethand
Contributor III
Contributor III

Sum distinct combining multiple conditions

I have data file like this (only an example):

 

Uniq_ID

Price1

Price2

weight

1

10

20

1,50

1

15

30

1,50

1

25

50

1,50

2

10

10

1,25

2

40

40

1,25

3

10

60

2,50

 

 

With one condition (variable ’ vMaxPrisKvm’ set with a slider) I can use this expression getting my desired result:

Sum({<[Price1] = {">=$(vPrice1)"}>}Aggr(Only([weight]), Uniq_ID))

 

If I set my slider to 30 the result will be ’1.25’ as Uniq-ID 2 is the only one with a Price1-value bigger than 30.

But now I like to sum distinct with two variables (Price1 and Price2).

 

If I set my first slider (Price1) to 30 and a second slider (Price2) to 55 the result should be 3.75 (sum of weight for Uniq_ID 2 and 3).

 

I have tried something like:

 

Sum({   <[Price1] = {">=$(vPrice1)"}> or <[Price2] = {">=$(vPrice2)"}>}Aggr(Only([weight]), Uniq_ID))

}Aggr(Only([weight]), Uniq_ID))

 

But the syntax using 'or' isn’t correct.

How do I do that?

1 Solution

Accepted Solutions
GaryGiles
Specialist
Specialist

Not sure about the rest of the equation, but in order to perform an "or" in set analysis, you need to use a "+" between the two sets <. . . >+<. . . >, like this.

Sum({<[Price1] = {">=$(vPrice1)"}>+<[Price2] = {">=$(vPrice2)"}>} Aggr(Only([weight]), Uniq_ID))

The data that you provide looks a little off, in terms of number of columns.  If you can put it in a Load Inline statement, it would make it easier to help.

 

View solution in original post

2 Replies
GaryGiles
Specialist
Specialist

Not sure about the rest of the equation, but in order to perform an "or" in set analysis, you need to use a "+" between the two sets <. . . >+<. . . >, like this.

Sum({<[Price1] = {">=$(vPrice1)"}>+<[Price2] = {">=$(vPrice2)"}>} Aggr(Only([weight]), Uniq_ID))

The data that you provide looks a little off, in terms of number of columns.  If you can put it in a Load Inline statement, it would make it easier to help.

 

kennethand
Contributor III
Contributor III
Author

Thanks a lot Gary - exactly what I was looking for.