Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count with Aggr()

I am trying to count the numbers of IDs where certain measures satisfied required conditions. But I am unable to get the right number, can someone point me to the right direction here. Below is my current code..

pick(match(d,'M1','M2','M3','M4')

,count(if(aggr(sum(M1),ID,Dim_01)>0,ID))

,count(if(aggr(sum(M2),ID,Dim_01)>0,ID))

,count(if(aggr(sum(M3),ID,Dim_01)>0,ID))

,count(if(aggr(sum(M4),ID,Dim_01)>0,ID))

)

4 Replies
Anonymous
Not applicable
Author

The numbers in your report shows count of distinct IDs . You could use NODISTINCT in the aggr function to get every ID provided your if condition is met.

pick

(match(d,'M1','M2','M3','M4')

,
count(if(aggr(NODISTINCT sum(M1),ID,Dim_01)>0,ID))

,
count(if(aggr(NODISTINCT sum(M2),ID,Dim_01)>0,ID))

,
count(if(aggr(NODISTINCT sum(M3),ID,Dim_01)>0,ID))

,
count(if(aggr(NODISTINCT sum(M4),ID,Dim_01)>0,ID))

)

I hope this helps!

MultiView

Not applicable
Author

try this

pick(match(d,'M1','M2','M3','M4')

,count(distinct if(aggr(sum(M1),ID,Dim_01)>0,ID))

,count(distinct if(aggr(sum(M2),ID,Dim_01)>0,ID))

,count(distinct if(aggr(sum(M3),ID,Dim_01)>0,ID))

,count(distinct if(aggr(sum(M4),ID,Dim_01)>0,ID))

)

Not applicable
Author

Hi MulitView,

thank you for your help.

What if I would like to count the number of distincts ID? I don't quite understand why I get 0 on some of the line items.

Not applicable
Author

Hi Vishwaranjan,

I think you expression produces the same result as mine.