Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
mindyckay
Partner - Contributor II
Partner - Contributor II

Return Dimension with Highest Percentage

Hi All,

I need help with some code.  This is for Qlik Sense.


Business Question:

Which age group has the highest percentage of surgery complications?

  - Age Group

  - SurgeryID

  - complicationYN = {'Yes'}


Percentage of surgeries with complications   ... this works

    = Count({<complicationYN = {'Yes'}>} SurgeryID)/Count(SurgeryID)

Age group with the highest count of surgeries      ..... this works

    = FirstSortedValue([Age Group], -Aggr(Count(distinct SurgeryID), [Age Group]))


Age group with the highest count of surgeries with complications  ..... these do NOT work   ... return a '-'

    = FirstSortedValue([Age Group], -Aggr(If(complicationYN = 'Yes', Count(distinct SurgeryID)), [Age Group]))

    = FirstSortedValue([Age Group], -Aggr(Count({<complicationYN = {'Yes'}>} distinct SurgeryID), [Age Group]))

    = If(complicationYN = 'Yes', FirstSortedValue([Age Group], -Aggr(Count(distinct SurgeryID), [Age Group])))

Age group with the highest percentage of surgeries with complications .....

   = ? ? ? ? ? ? ? ? ?

  

Age Groups# Surgeries# Complications% of Surgeries w/ Complications
0-9189168.5%
10-192012512.4%
20-29320247.5%
30-39315257.9%
40-491541610.4%
50-591400.0%
60-69100.0%
[Age Group]
# Surgeries = Count(SurgeryID)
# Complications =  Count({<complicationYN = {'Yes'}>} SurgeryID)
% of Surgeries w/ Complications =  Count({<complicationYN = {'Yes'}>} SurgeryID) / Count(SurgeryID)
Age Group w/Highest % of Complications =  ? ? ? ? ?

Thanks in advance,

Mindy

12 Replies
nsetty
Partner - Creator II
Partner - Creator II

Pls try below expression.

FirstSortedValue(DISTINCT [Age Group], -Aggr(count({<complicationYN={'Yes'}>}distinct SurgeryID), [Age Group]), 1)

ogautier62
Specialist II
Specialist II

Hi,

ok, with rank, not minus sign

so with :

=concat( if(aggr(num(rank(count({<complicationYN = {'Yes'}>} distinct SurgeryID))),[Age Group])=1,[Age Group]),'*')

I get :

timpoismans
Specialist
Specialist

Hi Mindy

Take a look at the following.

First table shows the calculations:

Highest Percentage.PNG

Following is a solution in the table:

Highest Percentage_1.PNG

Measure: Count({<complicationYN={'Yes'}>}complicationYN)/Count(SurgeryID)

This is done by applying the following settings:

Apply the following to the dimension Age Group:

Highest Percentage_Config1.PNG

Apply the following to the sorting of the dimension Age Group:

1. Sort by Expression

2. Use the same measure as the percentages were calculated as the sorting measure

3. Descending

Highest Percentage_Config2.PNG

Following is a solution in KPI:

Highest Percentage_2.PNG

Measure: Aggr(If(Rank((Count({<complicationYN={'Yes'}>}complicationYN)/Count(SurgeryID)))=1,[Age Group]),[Age Group])