Forum Discussion
Adjusting X-Axis Max with Visual Calculation for Stacked Bar Chart
- 1 year ago
Thanks for the detailed reply and all the suggestions, unfortunately:
- When used as visual calculations, they give the same result as above: selecting the total value * 1.1 not the value of the longest bar.
- When using ALLSELECTED() in a "normal" measure I get an error message:
What did work is this measure (not visual calculation) - (cyan rectangle in screenshot below)
max_by_type =1.1 * MAXX([dim_column],[measure])
Using the same syntax as visual calculation
vc = 1.1* MAXX(ROWS,[measure])
is not working (red rectangle in screenshot below)
- 1 year ago
Hi eneri ,
Your DAX measure using MAXX(VALUES(dim_column), [measure]) works correctly because it calculates the maximum total per bar via row context, whereas the visual calculation MAXX(ROWS, [measure]) fails for axis scaling since it evaluates across individual segments rather than entire rows, leading to incorrect results like the total sum instead of the maximum row.
Use this DAX measure to dynamically scale your axis based on the longest individual bar:
max_by_type =1.1 * MAXX([dim_column],[measure])
Replace dim_column with the dimension that defines each bar (example: Category, Type, etc.).
Use this measure (max_by_type) as a reference to x axis, set the x-axis maximum manually or use it in layout logic.
Please provide sampple data, so we can reproduce your requirement.
Hope this helps.
Best Regards,
Chaithra E.
Hi eneri ,
I see what's happening with your visual calculation. The issue is that MAXX is looking at the total values across all rows rather than finding the maximum value within individual stacked bars.
Here's how to fix this:
Solution 1: Use MAXX with the right context Instead of your current formula, try this visual calculation:
MaxBarLength = MAXX(ALLSELECTED(), [YourMeasure])
This should evaluate each row individually rather than summing everything up.
Solution 2: Create a measure first, then reference it Create a base measure that calculates your stacked values:
StackedValue = SUM([YourColumn])
Then use this in your visual calculation:
AxisMax = 1.1 * MAXX(ALLSELECTED(), [StackedValue])
Solution 3: Use SUMMARIZE for row-level calculations
MaxIndividualBar =
1.1 * MAXX(
SUMMARIZE(
ALLSELECTED(),
[dim1],
"RowTotal", [YourMeasure]
),
[RowTotal]
)The key is making sure your calculation evaluates at the row level, not across the entire dataset. Visual calculations sometimes need explicit context to work properly with stacked visuals.
Try Solution 1 first as it's the simplest approach. You can find more details about visual calculations in the Power BI visual calculations documentation.
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes.
Thanks for the detailed reply and all the suggestions, unfortunately:
- When used as visual calculations, they give the same result as above: selecting the total value * 1.1 not the value of the longest bar.
- When using ALLSELECTED() in a "normal" measure I get an error message:
What did work is this measure (not visual calculation) - (cyan rectangle in screenshot below)
max_by_type =1.1 * MAXX([dim_column],[measure])
Using the same syntax as visual calculation
vc = 1.1* MAXX(ROWS,[measure])
is not working (red rectangle in screenshot below)
- eneri1 year ago
Helper I
It's not really a "solution" as it's not using a visual calculation as requested in the initial post. But MS Community Support seems to be eager to mark any topic as solved ...