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: 
Not applicable

count distinct IF sum

Hi,

I'm creating a line chart with month, and count().

count ( distinct Customer_Code)

How can i do the distinct count with IF statement. says count distinct customer if they sales is more than certain amount?

I tried :

if (sum(sales) <> 0 , count ( distinct Customer_Code))

But it's not working. and SET can't do sum() within it. any other alternatives?

Thanks

1 Solution

Accepted Solutions
Not applicable
Author

I would go with:

count(distinct aggr(if(sum(Sales)>100000,CustomerId),CustomerId))

View solution in original post

7 Replies
Not applicable
Author

Bro ,

You can try this...........

=

count({$<sum(SalesDetail_Amt) <>{'0'}>} distinct CUSTOMER_ID )



Not applicable
Author

Hi Dushyant,

Thanks for the suggestion. But i think in SET, we can't use functions like sum().

I'm not sure how true, but it doesn't work for me.

pat_agen
Specialist
Specialist

hi,

use the aggr function for this:

Count (distinct if(aggr(sum(Sales),CustomerId)>0, CustomerId))

hope this helps.

Not applicable
Author

Thanks, but still not working.... Sad

Not applicable
Author

in fact, i need to do <> '0'.

funny thing is, i can get the correct count when i do = '0'

but wrong count for <> ' 0 '

in my data, there are negative values , positive values , and 0.

ToniKautto
Employee
Employee

I'm a bit unsure if the previous aggr-function works, since the aggr will return a data set and not a numeric value. Try adding an additional sum of the aggr to make the result numerical.

Count ( distinct if( sum ( aggr ( sum(Sales), CustomerId) ) >0, CustomerId) )



Not applicable
Author

I would go with:

count(distinct aggr(if(sum(Sales)>100000,CustomerId),CustomerId))