# App Development

Announcements
Support Cases coming to Qlik Community Oct. 4! Start chats, open cases, explore resources: READ DETAILS
cancel
Showing results for
Did you mean:
Specialist

## Set Analysis with FirstSortedValue

I'd like to count the number of patients whose last blood pressure in the year was below 140. I am able to find the value of the last blood pressure like this in a chart:

=FirstSortedValue({<IsSameYear={1}, FactType={BP}>} [BP SYSTOLIC], -Date)

This correctly returns the value every time.

When I try to count patients for whom this is true, it does not work. My measure:

=Count(distinct {<PatientID={"=(FirstSortedValue({<IsSameYear={1}, FactType={BP}>} [BP SYSTOLIC], -Date)<140)"}>} PatientID)

Any clues why this does not work?

1 Solution

Accepted Solutions
MVP

Hi

Try like below

Sum(Aggr(If(FirstSortedValue({<IsSameYear={1}, FactType={BP}>} [BP SYSTOLIC], -Date) < 140, 1), PatientID))

Thanks & Regards,
Mayil Vahanan R
3 Replies
MVP

Hi

Try like below

Sum(Aggr(If(FirstSortedValue({<IsSameYear={1}, FactType={BP}>} [BP SYSTOLIC], -Date) < 140, 1), PatientID))

Thanks & Regards,
Mayil Vahanan R
Master

HI,

Try below expression

count({DISTINCT< PatientID={" =Aggr(FirstSortedValue({<IsSameYear={1}, FactType={BP}>} [BP SYSTOLIC], -Date),PatientID)<140"}>}PatientID)

Specialist
Author

Thank you both, Sasi and Mayil. You got me on the right track with Aggr, this way:

count(DISTINCT If(aggr({<IsSameYear={1}, AsOfYear>} FirstSortedValue({<IsSameYear={1}, FactType={BP}>} [BP SYSTOLIC], -Date), PatientID, AsOfYear)<140, PatientID))

Tags
Community Browser