Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
david777
Contributor II
Contributor II

Count distinct

Hi

Can anyone tell me how to count distinct pnr if hba1c is greater than 70 only for the last row for each pnr in the table below?

So person 62811 should't count because the last value is 60.

persondatevalue
893762012-11-2972
228602012-03-0782
033172012-12-1282
735572012-03-2385
628112012-05-0273
628112012-08-3160
133252012-02-22107
090812012-03-2172
233052012-04-1075
233362012-05-1456
233362012-05-1572
233362012-06-1540
233362012-08-1433
135412012-05-1474
734132012-08-2887
1 Solution

Accepted Solutions
rubenmarin

Hi David, you can use:

=Sum(Aggr(If(FirstSortedValue(Value, -Date)>70, 1, 0), Person))

It will fail if the same Person have different values for the same date.

View solution in original post

5 Replies
datanibbler
Champion
Champion

Hi David,

there are several ways, but Set_analysis would probably be the most elegant.

Just put sth like

COUNT({$<value = {$(= '>' & '70')}>} DISTINCT  pnr)

HTH

Best regards,

DataNibbler

sunny_talwar

Hey David,

Please check the attached qvw and see if this is what you want.

Best,

S

agomes1971
Specialist II
Specialist II

Hi,

that's a nit approach!!!

Regards

André Gomes

rubenmarin

Hi David, you can use:

=Sum(Aggr(If(FirstSortedValue(Value, -Date)>70, 1, 0), Person))

It will fail if the same Person have different values for the same date.

sunny_talwar

That's a very sleek way of doing it. I am glad I saw your method. Thanks for sharing it.

Best,

S