Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

how to show column total in stacked column chart where measure is a ratio

I want to show the total of the segments in a stacked column chart.  However, because my measure is a ratio, I don't think the usual solution pattern (https://radacad.com/showing-the-total-value-in-stacked-column-chart-in-power-bi) applies (at least, not without modification).  My report is about timesheet compliance for employees.  Below is a sample of the only table in my data model:

Employee KeyEmployee Category 1Employee Category 2Day KeyWeek KeyHours EnteredHours Expected
1AxMonday108
1AxTuesday188
1AxWednesday188
1AxThursday108
1AxFriday188
2ByMonday188
2ByTuesday188
2ByWednesday108
2ByThursday188
2ByFriday188

 

Timesheet compliance is defined as the number of hours entered as a percentage of the hours expected.  I want to show this on a stacked column chart, where x axis = [Week Key] and legend = [Day Key].  I want to show this at both the atomic employee level, their rollups (by [Employee Category 1] and [Employee Category 2]), and at the company level.  So, I have put [Employee Key], [Employee Category 1], and [Employee Category 2] as fields in the filter pane, and I have created 3 measures (not calculated columns, because the final measure is a ratio):

[Sum of Hours Entered] = SUM('Table'[Hours Entered])

[Sum of Hours Expected] = SUM('Table'[Hours Expected])

[Timesheet Compliance] = DIVIDE([Sum of Hours Entered], [Sum of Hours Expected], 0)

 

All of this works as desired.  However, in order to show the sum (total) of each of the column segments, the usual solution (convert to stacked column and line chart, use the same measure in both Column values and in Line values, i.e., [Timesheet Compliance]) will not work.  Using [Timesheet Compliance] for Line values does not return the sum of each column segment.  Instead, it returns an overall ratio.  How can I return the sum of each column segment, ensuring that this value is valid for any selection of the fields in my filter pane?

1 ACCEPTED SOLUTION

Hi  @Anonymous ,

 

I have modified the column to below measures:

 

_sum of hours entered = 
SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])&&'Table'[Day Key]=MAX('Table'[Day Key])),'Table'[Hour Entered])
_sum of hours expected = 
SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])&&'Table'[Day Key]=MAX('Table'[Day Key])),'Table'[Hour Expected])
_Timesheet = DIVIDE([_sum of hours entered],'Table'[_sum of hours expected])
_Total timesheet = SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])&&'Table'[Employee Key]=MAX('Table'[Employee Key])),[_Timesheet])

 

Then you can use the filters as you hope.

Annotation 2020-05-26 142614.png

Here is the modified .pbix file.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

8 REPLIES 8
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try to modify your measure as below:

 

 

 

Sum of Hours Expected = SUMX(FILTER(ALL('Table'),'Table'[Employee Category 1]=MAX('Table'[Employee Category 1])&&'Table'[Day Key]=MAX('Table'[Day Key])&&'Table'[Week Key]=MAX('Table'[Week Key])),'Table'[Hours Expected])
Sum of Hours Entered = SUMX(FILTER(ALL('Table'),'Table'[Employee Category 1]=MAX('Table'[Employee Category 1])&&'Table'[Day Key]=MAX('Table'[Day Key])&&'Table'[Week Key]=MAX('Table'[Week Key])),'Table'[Hours Entered])
[Timesheet Compliance] = DIVIDE([Sum of Hours Entered], [Sum of Hours Expected], 0)

 

 

 

If it doesnt work,pls advise me your expected output,and if possible,pls provide me your .pbix file.

Much appreciated.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Anonymous
Not applicable

@v-kelly-msft 

 

That solution did not work.  And, it made my column segments incorrect.  Here is what your solution produces:

 

4.png

 

Here is my data, my computations (for the "no filter selection" scenario), and my expected output:

1.png

 

2.png3.png

Hi @Anonymous ,

 

You need 2 calculated columns as below:

 

sum of hours entered = 
var preindex= CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Day Key]=EARLIER('Table'[Day Key])&&'Table'[Week key]=EARLIER('Table'[Week key])))
Return
IF('Table'[Index]=preindex,BLANK(),'Table'[Hour Entered]+SUMX(FILTER('Table','Table'[Index]=preindex),'Table'[Hour Entered]))
sum of hours expected = 
var preindex= CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Day Key]=EARLIER('Table'[Day Key])&&'Table'[Week key]=EARLIER('Table'[Week key])))
Return
IF('Table'[Index]=preindex,BLANK(),'Table'[Hour Expected]+SUMX(FILTER('Table','Table'[Index]=preindex),'Table'[Hour Expected]))

 

And 2 measures as below:

 

Timesheet = DIVIDE(MAX('Table'[sum of hours entered]),MAX('Table'[sum of hours expected]))
Total Timesheet = SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])),'Table'[Timesheet])

 

If you wanna show total in the stacked column chart,you'd better change the visual to "Line and stacked column chart",and under "format">"shape",choose "stroke width" to "0",shown as below:

Annotation 2020-05-15 093530.png

Finally you will see:

Annotation 2020-05-15 093709.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

Anonymous
Not applicable

@v-kelly-msft 
Is there any way to modify this solution so that the visuals reflect filter pane selections?  Even though this solution works at the company level, I need it to also work at any given employee rollup level (e.g., [Employee Category 1] or [Employee Category 2]) and the employee level (i.e., [Employee Key]).  That is why I have fields [Employee Category 1], [Employee Category 2], and [Employee Key] in my filter pane.  When I select anything about employee #1, there is no change to the visuals.  When I select anything about employee #2, the stacked column + line chart disappears, and all fields in the table visual except for [Week key], [Date Key], and [Total Timesheet] turn blank.  To be sure, if it matters, in my actual pbix file, each [Employee Category 1] and [Employee Category 2] value will appear on multiple employees (e.g., employee #3 could have combination A-y, and employee #4 could have combination B-x).

Anonymous
Not applicable

@v-kelly-msft 

Any ideas on how to make this solution also work to reflect filter context (i.e., filter pane selections)?

Hi  @Anonymous ,

 

I have modified the column to below measures:

 

_sum of hours entered = 
SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])&&'Table'[Day Key]=MAX('Table'[Day Key])),'Table'[Hour Entered])
_sum of hours expected = 
SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])&&'Table'[Day Key]=MAX('Table'[Day Key])),'Table'[Hour Expected])
_Timesheet = DIVIDE([_sum of hours entered],'Table'[_sum of hours expected])
_Total timesheet = SUMX(FILTER(ALL('Table'),'Table'[Week key]=MAX('Table'[Week key])&&'Table'[Employee Key]=MAX('Table'[Employee Key])),[_Timesheet])

 

Then you can use the filters as you hope.

Annotation 2020-05-26 142614.png

Here is the modified .pbix file.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

Hi @Anonymous ,

 

Can you upload your .pbix file to onedrive business and share the link with me?Better attach your expected output.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Anonymous
Not applicable

I can't share my pbix file with you, as my company has disabled all external sharing in our tenant.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors