Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

SUM 2 conditional counts

I´m trying to sum 2 counts like this, but i get no result

SUM(Count(if(category='x', item))+ (Count(if(category='y', item))

Labels (1)
1 Solution

Accepted Solutions
Not applicable
Author

Hi Polschou,

why you use sum?

you can get the result direct with

Count(if(category='x' or category='y', item))

and try to use set anylasis as following

count({<category={'x','y'}>} item)

hope this help you

View solution in original post

5 Replies
brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi,

you have to use the AGGR function, if you use two aggregation functions like this:

Sum(Aggr(Count(if(category='x', item)),Dimension))+ Sum(Aggr(Count(if(category='y', item)),Dimension))

or

Sum(Aggr(Count(if(category='x' or category='y', item)),Dimension

with more performance I would recommend this:

Sum(Aggr(Sum(if(category='x' or category='y', 1,0)),Dimension))

Dimension can be more than one: Dim1,Dim2,Dim3,...

Not applicable
Author

Hi Polschou,

why you use sum?

you can get the result direct with

Count(if(category='x' or category='y', item))

and try to use set anylasis as following

count({<category={'x','y'}>} item)

hope this help you

Not applicable
Author

Hi Martina

I tried somthing else and it seems to work for me - I use this to add the 2 conditions

COUNT(IF(categori='x' OR categori='y',item))

Not applicable
Author

Hi  Mohammed

If I want to add another condition like this

COUNT(IF(categori='x' OR categori='y' AND YEAR='2011',item)) - but this gives a wrong result - I cant attach a

QW file

Not applicable
Author

Hi polschou

i think it should be like the following:

COUNT(IF((categori='x' OR categori='y' ) AND YEAR='2011',item))

count({<categori={'x','y'},YEAR='2011'>} item)

the diffrent is ( ) between Category and Year

hope this help you.