Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Lauri
Specialist
Specialist

Count distinct, but only once per dimension

I have a table with a dimension (Clinic) and a measure (count of distinct patients who had a visit). How can I make the measure count patients only once in the table, for their most recent visit?

For example, the Clinic dimension has values 'Clinic A' and 'Clinic B.' If patient Mary went to both clinics, she should be counted in the 'Clinic A' row because she went there most recently.

In the data model, the fields are all in one table: Clinic, PatientID, VisitDate.

Should I use set analysis with Aggr? 

Labels (1)
2 Replies
Vegar
MVP
MVP

You could try this expression:

=-SUM(Clinic=aggr(nodistinct FirstSortedValue(Clinic, -VisitDate),PatientID))

Lauri
Specialist
Specialist
Author

Thank you, @Vegar . I don't completely understand. Do you mean that can be my measure expression? Or is that set analysis inside of count(distinct PatientID)? It looks like set analysis but without {} and <> brackets.