Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Q&A with Qlik - Qlik Cloud Migration: Questions about migrating to Qlik Cloud? Catch the latest replay!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Computing percentages in a stacked bar chart

Hi,

I am working on a stacked bar chart.  I have two dimensions.

Dimension 1 is a group named Year.  It has 3 drill down levels: Fiscal Year, Quarter, and Month

Dimension 2 is a calculated dimension based on the values in a variable:

=aggr(if($(ComputedBench)='25th', $(ComputedBench),

if($(ComputedBench) = '50th', $(ComputedBench),

if($(ComputedBench) = '75th', $(ComputedBench),

if($(ComputedBench) = 'Over 75th', $(ComputedBench))))),

FACNUM, Year)

ComputedBench is a variable that contains 25th, 50th, 75th, Over 75th or Null.

I tried this expression to compute the percentages, but no data was displayed in my chart:

=count($(ComputedBench))/aggr(NODISTINCT Count($(ComputedBench)),Year)

I  tried changing it to this expression thinking that counting a value from a variable may be the issue, but the calculation seems to be off since the 4 stacks (based on dimension 2) on my bar chart do not add up to 100%. 

=Count(NormTotalExpenseEVS)/aggr(NODISTINCT Count(NormTotalExpenseEVS),Year)

NormTotalExpenseEVS is a field in a table.  If a center has NormTotalExpenseEVS filled in, then ComputedBench should definitely have a value other than NULL.

Does anyone have any suggestions about how to make this work?

Thank You!

Labels (1)
3 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Try something like this:

=Count(NormTotalExpenseEVS)/Count( TOTAL <Year> NormTotalExpenseEVS)


or, for a dynamic group, try this:


=Count(NormTotalExpenseEVS)/Count( TOTAL <$(=GetCurrentField(MyGroup))> NormTotalExpenseEVS)


when calculating subtotals by chart dimensions, using TOTAL works much better than using AGGR.


cheers,


Oleg Troyansky

www.masterssummit.com

www.naturalsynergies.com


Ask me about Qlik Sense Expert Class!
Not applicable
Author

Thanks for the response. I tried the =Count(NormTotalExpenseEVS)/Count( TOTAL <Year> NormTotalExpenseEVS).  My chart showed 100% for all of the dimensions, so I dumped the expressions into a pivot table to look at the pieces of the expression (results are below). 

MonthQuartileTotalExpenseperAPDNumeratorDenominator
OctoberOver 75th100%3131
October75th100%4646
October50th100%5454
October25th100%6565

The numerators are correct, but the denominator should be equal to the sum of the numerators for all quartiles combined, which in this case should be 196 for each of these.  It looks like it is only considering the quartile in the current dimension when computing the denominators. Any ideas how to get around this?

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Shannon,

if you first dimension is Month, then you should use Month as a qualifier for the TOTAL:

Count(NormTotalExpenseEVS)/Count( TOTAL <Month> NormTotalExpenseEVS)

Or, use GetCurrentField() to make the expression work with a dynamic group

Ask me about Qlik Sense Expert Class!