Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
sgagliardi
Partner - Contributor III
Partner - Contributor III

Count all possible from alternate state

Hey Qlik Sense Community, reaching out because I am at the end of my rope with a particular problem.

In a KPI object in an alternate state, I am attempting to count all possible encounter numbers of patient numbers that are currently selected in the default state. What I have written works great when the selections I have made in the default state are 1-to-1  with the patient number, but when there are multiple instances of the same patient number, Qlik Sense throws out all countable encounters, returning 0 for that count. Here is what I have written:

count(distinct aggr(nodistinct only({$<[Encounter Number]=P([Encounter Number])>}[Encounter Number]),[Patient Number]))))

Imagine the table looks something like:

[Patient Number][Encounter Number][Diagnosis]
13571234470
24685678871
57909101470
12561213470
23671415871
13571617470
26751819234

 

I have selected in the default state the Diagnosis 470. I would expect my KPI to return 4, though it returns 2, as patient number 1357 occurs twice. When I select Diagnosis 871, I return 2, and I select Diagnosis 234, I return 1.

Any thoughts here would be super helpful. I've played around with this for a couple of weeks, but this is as close as I've gotten. I suspect maybe there is a conflict of some sort around the distinct/nodistinct usage, but I have not  been able to figure it out.

14 Replies
sgagliardi
Partner - Contributor III
Partner - Contributor III
Author

I finally figured it out. If anyone is interested, below is my solution:

=count({1<[Patient ID]=p({<[Patient ID]>}),[Admit Date]={"$(= '>=' & date($(DateofIndex)+$(ContinuumB)) & '<=' & date($(DateofIndex)+$(ContinuumA)))"}>} distinct [Encounter Number])

//$(DateofIndex)=aggr(if(rank(num([Admit Date]))=1,[Admit Date]),[Encounter Number])
//$(ContinuumA)= User Input
//$(ContinuumB)= User Input

tresesco
MVP
MVP

Great! So the date range condition finally within the count(). 🙂  

sgagliardi
Partner - Contributor III
Partner - Contributor III
Author

Hey @tresesco 

Yes! I credit you with the solution on this one for providing me the inspiration to approach it from another angle.

I feel like I've ALMOST got it down, but now I am struggling with the rank() function I'm using in the one variable to grab earliest occurring admit date for the selected encounter numbers for each patient number. What the code is doing now is grabbing earliest admit date for the full selection, and not for each patient number. As a result, the date range build in set analysis considerably skews the count. Stumped again.

aggr(if(rank([Admit Date])=1,[Admit Date]),[Encounter Number])

tresesco
MVP
MVP

May be include the patient dimension as well in aggr(), like:

aggr(if(rank([Admit Date])=1,[Admit Date]),[Patient ID],[Encounter Number])

sgagliardi
Partner - Contributor III
Partner - Contributor III
Author

Hi @tresesco ,

Thanks for the suggestion! This returns for me the full sum or total, seemingly disregarding the date range that's being established in the set analysis.

I wonder however if perhaps this is creating the behavior I'm after, but instead counting encounters with admit dates occurring in any of the ranges being dynamically created for each MRN in the selection...

Still pecking away at it, this is proving to be a tricky problem.