The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi Team,
I am facing a critical issue in Power BI related to the Stacked Column Chart total data labels.
I have a Stacked Column Chart where I want to display the sum of average durations of CycleTime (cycletime_nm) on top of the bar.
The bar height should reflect the average, but the label on top of the bar should show the sum of selected cycle times.
When I select a single cycletime_nm, the total label shows correct values.
When I multi-select a few cycle times, it sums correctly and displays the accurate total label.
But when no filter is applied (i.e., default view, all cycle times selected), the bar total label shows incorrect/inflated values.
Y-axis showing Average
Bar labels showing SUM of averages for selected cycle times
Correct totals even in default view when no slicer selection is made.
Dax im using:
Main Switch Measure (for Days/Hours/Minutes Selection):
sum_Avg.Duration DaysHours =
SWITCH(
SELECTEDVALUE(DayHour[DayHour], "Minutes"),
"Minutes", [sm_MinutesCalc],
"Days", [sm_DaysCalc],
"Hours", [sm_HoursCalc]
)
Days Calculation (Sum of Averages per CycleTime):
sm_DaysCalc =
VAR CycleTimeList = VALUES(CycleTime_IHA_POM_Sliver[cycletime_nm])
RETURN
SUMX(
CycleTimeList,
CALCULATE(AVERAGE(CycleTime_IHA_POM_Sliver[avgdurationdays]))
)
avgdurationdays Calculation:
avgdurationdays = CycleTime_IHA_POM_Sliver[cycletime_duration_mi] / 1440
Hours Calculation (Sum of Averages per CycleTime):
sm_HoursCalc =
VAR CycleTimeList = VALUES(CycleTime_IHA_POM_Sliver[cycletime_nm])
RETURN
SUMX(
CycleTimeList,
CALCULATE(AVERAGE(CycleTime_IHA_POM_Sliver[AvgDurationHrs]))
)
AvgDurationHrs Calculation:
AvgDurationHrs = CycleTime_IHA_POM_Sliver[avgdurationdays] * 24
Minutes Calculation (Sum of Averages per CycleTime):
sm_MinutesCalc =
VAR CycleTimeList = VALUES(CycleTime_IHA_POM_Sliver[cycletime_nm])
RETURN
SUMX(
CycleTimeList,
CALCULATE(AVERAGE(CycleTime_IHA_POM_Sliver[cycletime_duration_mi]))
)
The data label on top should always reflect the sum of averages of selected cycletime_nm values.
The current DAX works fine when specific cycle times are selected.
However, in the default state (all cycle times selected), the SUMX adds up the averages in a way that inflates the total bar label, leading to incorrect values.
For example, in January 2024, the actual sum of averages is 6.84, but it shows as 17.15.
I need help modifying the DAX to ensure that:
The Total data label always shows the correct sum of averages (even when all cycle times are selected).
The Y-axis can remain as Average, but the label should always display sum of selected cycle times averages.
Also, if there's a better visual/approach to handle this scenario, I'm open to recommendations.
Thank you
Solved! Go to Solution.
Hi @azeenk ,
This is a classic and interesting DAX problem. The behavior you're observing, where the total is incorrect only in the unfiltered "grand total" context, points to a subtle issue with how filter context is being handled. Your current SUMX(VALUES(...)) pattern is designed to iterate through each cycletime_nm, calculate its average, and then sum those averages. While this logic appears sound, it can become unreliable when Power BI calculates the chart's total data label. In that specific context, which lacks a filter from the chart's legend, the context transition within SUMX can sometimes interact with the data model in unexpected ways, leading to the inflated values you've described.
To resolve this, we can use a more robust DAX pattern employing the SUMMARIZE function. This approach is generally more stable because it first creates an explicit virtual summary table of the averages for each group before summing the results, making it less susceptible to these context transition issues. By replacing your current measures with this pattern, you will get accurate totals in all scenarios, including the default view.
Here is the revised DAX for your sm_DaysCalc measure. It first generates a table of each cycle time and its average duration, then sums those averages.
sm_DaysCalc =
VAR SummaryTable =
SUMMARIZE(
CycleTime_IHA_POM_Sliver,
CycleTime_IHA_POM_Sliver[cycletime_nm],
"__AverageDuration", AVERAGE(CycleTime_IHA_POM_Sliver[avgdurationdays])
)
RETURN
SUMX(
SummaryTable,
[__AverageDuration]
)
You should apply the same robust pattern for the hours calculation.
sm_HoursCalc =
VAR SummaryTable =
SUMMARIZE(
CycleTime_IHA_POM_Sliver,
CycleTime_IHA_POM_Sliver[cycletime_nm],
"__AverageDurationHrs", AVERAGE(CycleTime_IHA_POM_Sliver[AvgDurationHrs])
)
RETURN
SUMX(
SummaryTable,
[__AverageDurationHrs]
)
And finally, update the minutes calculation with the SUMMARIZE logic as well.
sm_MinutesCalc =
VAR SummaryTable =
SUMMARIZE(
CycleTime_IHA_POM_Sliver,
CycleTime_IHA_POM_Sliver[cycletime_nm],
"__AverageDurationMins", AVERAGE(CycleTime_IHA_POM_Sliver[cycletime_duration_mi])
)
RETURN
SUMX(
SummaryTable,
[__AverageDurationMins]
)
Regarding your goal to have the Y-axis show an "Average" while the label shows a "Sum," it's important to clarify how the stacked column chart functions. The total height of a stacked bar is the direct sum of its individual segments, and the total data label simply displays this total value. It's not possible to have the bar's total height represent one metric and the label show a different one. The revised DAX measures above correctly set the value for each segment to its specific average.
Consequently, the total bar height and the total data label will both accurately reflect the sum of those averages, which aligns with your core requirement.
Although the DAX above fixes the calculation, summing averages can sometimes be a less meaningful metric than a true overall average. You might consider an alternative visual approach for greater clarity. One option is to use Small Multiples, where you place the cycletime_nm field in the "Small multiples" well of a standard column chart. This creates a separate chart for each cycle time, allowing for direct comparison of their individual averages without needing to sum them. For this, you would use a simple average measure instead of a "sum of averages" measure.
Another powerful alternative is the "Line and stacked column chart." You can use your revised SUMMARIZE-based measure for the column values to show the stacked "sum of averages," and then add a second, simpler measure to the line value to plot the true overall average across all selected cycle times. This provides a rich view, showing both the composition of the parts and the true average of the whole on a single visual. The measure for the line would simply be:
Overall Average Days = AVERAGE(CycleTime_IHA_POM_Sliver[avgdurationdays])
Best regards,
Hello @azeenk,
Thank you for reaching out to the Microsoft Fabric Community Forum.
I have reproduced your scenario in Power BI Desktop and I’m able to achieve the expected behavior using a card visual to display the sum of visible average durations. The stacked column chart shows average per cycle time as intended.
For your reference, I’m attaching the .pbix file with the working solution.
Best Regards,
Ganesh singamshetty.
Hello @azeenk,
Could you please confirm if your query has been resolved by the provided solutions? This would be helpful for other members who may encounter similar issues.
Thank you for being part of the Microsoft Fabric Community.
Hello @azeenk,
Hope everything’s going great with you. Just checking in has the issue been resolved or are you still running into problems? Sharing an update can really help others facing the same thing.
Thank you.
Hello @azeenk,
We hope you're doing well. Could you please confirm whether your issue has been resolved or if you're still facing challenges? Your update will be valuable to the community and may assist others with similar concerns.
Thank you.
Hello @azeenk,
Thank you for reaching out to the Microsoft Fabric Community Forum.
I have reproduced your scenario in Power BI Desktop and I’m able to achieve the expected behavior using a card visual to display the sum of visible average durations. The stacked column chart shows average per cycle time as intended.
For your reference, I’m attaching the .pbix file with the working solution.
Best Regards,
Ganesh singamshetty.
Hi @azeenk
Instead of using VALUES(cycletime_nm), use SUMMARIZE or DISTINCT over the visual context. You can use ALLSELECTED to respect slicer and visual filters
sm_DaysCalc_Corrected =
VAR CycleTimeList =
SUMMARIZE(
ALLSELECTED(CycleTime_IHA_POM_Sliver),
CycleTime_IHA_POM_Sliver[cycletime_nm]
)
RETURN
SUMX(
CycleTimeList,
CALCULATE(AVERAGE(CycleTime_IHA_POM_Sliver[avgdurationdays]))
)
Repeat for sm_HoursCalc and sm_MinutesCalc
Make sure your switch measure uses the corrected versions
sum_Avg.Duration DaysHours =
SWITCH(
SELECTEDVALUE(DayHour[DayHour], "Minutes"),
"Minutes", [sm_MinutesCalc_Corrected],
"Days", [sm_DaysCalc_Corrected],
"Hours", [sm_HoursCalc_Corrected]
)
I hope this helps, please give a thumbs up and mark as solved if it does, thanks!
Hi @azeenk ,
This is a classic and interesting DAX problem. The behavior you're observing, where the total is incorrect only in the unfiltered "grand total" context, points to a subtle issue with how filter context is being handled. Your current SUMX(VALUES(...)) pattern is designed to iterate through each cycletime_nm, calculate its average, and then sum those averages. While this logic appears sound, it can become unreliable when Power BI calculates the chart's total data label. In that specific context, which lacks a filter from the chart's legend, the context transition within SUMX can sometimes interact with the data model in unexpected ways, leading to the inflated values you've described.
To resolve this, we can use a more robust DAX pattern employing the SUMMARIZE function. This approach is generally more stable because it first creates an explicit virtual summary table of the averages for each group before summing the results, making it less susceptible to these context transition issues. By replacing your current measures with this pattern, you will get accurate totals in all scenarios, including the default view.
Here is the revised DAX for your sm_DaysCalc measure. It first generates a table of each cycle time and its average duration, then sums those averages.
sm_DaysCalc =
VAR SummaryTable =
SUMMARIZE(
CycleTime_IHA_POM_Sliver,
CycleTime_IHA_POM_Sliver[cycletime_nm],
"__AverageDuration", AVERAGE(CycleTime_IHA_POM_Sliver[avgdurationdays])
)
RETURN
SUMX(
SummaryTable,
[__AverageDuration]
)
You should apply the same robust pattern for the hours calculation.
sm_HoursCalc =
VAR SummaryTable =
SUMMARIZE(
CycleTime_IHA_POM_Sliver,
CycleTime_IHA_POM_Sliver[cycletime_nm],
"__AverageDurationHrs", AVERAGE(CycleTime_IHA_POM_Sliver[AvgDurationHrs])
)
RETURN
SUMX(
SummaryTable,
[__AverageDurationHrs]
)
And finally, update the minutes calculation with the SUMMARIZE logic as well.
sm_MinutesCalc =
VAR SummaryTable =
SUMMARIZE(
CycleTime_IHA_POM_Sliver,
CycleTime_IHA_POM_Sliver[cycletime_nm],
"__AverageDurationMins", AVERAGE(CycleTime_IHA_POM_Sliver[cycletime_duration_mi])
)
RETURN
SUMX(
SummaryTable,
[__AverageDurationMins]
)
Regarding your goal to have the Y-axis show an "Average" while the label shows a "Sum," it's important to clarify how the stacked column chart functions. The total height of a stacked bar is the direct sum of its individual segments, and the total data label simply displays this total value. It's not possible to have the bar's total height represent one metric and the label show a different one. The revised DAX measures above correctly set the value for each segment to its specific average.
Consequently, the total bar height and the total data label will both accurately reflect the sum of those averages, which aligns with your core requirement.
Although the DAX above fixes the calculation, summing averages can sometimes be a less meaningful metric than a true overall average. You might consider an alternative visual approach for greater clarity. One option is to use Small Multiples, where you place the cycletime_nm field in the "Small multiples" well of a standard column chart. This creates a separate chart for each cycle time, allowing for direct comparison of their individual averages without needing to sum them. For this, you would use a simple average measure instead of a "sum of averages" measure.
Another powerful alternative is the "Line and stacked column chart." You can use your revised SUMMARIZE-based measure for the column values to show the stacked "sum of averages," and then add a second, simpler measure to the line value to plot the true overall average across all selected cycle times. This provides a rich view, showing both the composition of the parts and the true average of the whole on a single visual. The measure for the line would simply be:
Overall Average Days = AVERAGE(CycleTime_IHA_POM_Sliver[avgdurationdays])
Best regards,
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
27 | |
19 | |
13 | |
9 | |
5 |