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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
curiousfellow
Specialist
Specialist

Aggr count distinct

Please have a look at the simplified example of my qvw.

An employee works for two departments. I have to count the distinct months this employee works.

I wonder why the result is presented at just one department. I need the result for both of the departments 

 

We are using version  april 2019

1 Solution

Accepted Solutions
MayilVahanan

Hi

Might be, try like below

=Sum(Total Aggr(Count( DISTINCT month), employee))

MayilVahanan_0-1618297592218.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

6 Replies
rubenmarin

Hi, to count each dept you need to add dept as another dimension for the aggr:

=aggr(count (distinct month),employee,dept)

Which at the end is the same than just: count(DISTINCT month) // But maybe in the not-simplified version of the qvw makes sense to use the aggr

curiousfellow
Specialist
Specialist
Author

When I use : =aggr(count (distinct month),employee,dept) the result for dept A = 6 and for dept B = 4

For both dept's the result should be 6 this employee works in 6 several months

MayilVahanan

Hi @curiousfellow 

May be, try like below

=Count(TOTAL<employee> DISTINCT month)

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
curiousfellow
Specialist
Specialist
Author

I tried that one before. When dept is collapsed the result are correct, but when I expand dept A (employee gets visible) than B shows 4 months as a result.  When both dept's are epandend the result is ok.

When I expand dept B and A = collapsed B shows 4 as a result.

 

MayilVahanan

Hi

Might be, try like below

=Sum(Total Aggr(Count( DISTINCT month), employee))

MayilVahanan_0-1618297592218.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
curiousfellow
Specialist
Specialist
Author

Seems to work, thank you very much.