Forum Discussion
dynamic format string causing incorrect Y scale
- 18 days ago
Hi powerbiexpert22,
The problem is in the format string expression itself. It returns FORMAT(SelectedMeasure, ...), which is the already-formatted value (for example "12.3M"), not a format pattern.
Power BI then uses that text as the pattern for every number on the axis. Characters that aren't format placeholders are printed literally, so every tick shows the same "12.3M". That is the repeated value you are seeing.
current: format string expr -> FORMAT(value, "#,0.0,,M") -> "12.3M" axis tick 0, 5M, 10M, 15M -> each rendered with pattern "12.3M" -> "12.3M", "12.3M", "12.3M" ... fix: format string expr -> "#,0.0,,\"M\"" axis tick 5000000 -> "5.0M", 10000000 -> "10.0M"Return only the pattern, and use SELECTEDMEASURE() so it works no matter which measure the calc item or field parameter switches to:
VAR v = ABS ( SELECTEDMEASURE () ) RETURN SWITCH ( TRUE (), v < 1e3, "#,0", v < 1e6, "#,0.0,\"K\"", v < 1e9, "#,0.0,,\"M\"", "#,0.0,,,\"B\"" )Each comma after the 0 divides by 1,000. Literal letters belong in escaped quotes so K/M/B aren't read as format codes.
One more thing to expect: the axis uses a single format string for the whole axis, evaluated at the visual (total) level. If the total is in millions, all ticks show in M, even the small ones. That is usually what you want. If not, set the Y axis Display units manually and the data labels keep the dynamic format.
So my overall approach would be:
format string expression returns a pattern, never FORMAT() -> use SELECTEDMEASURE() + escaped "K"/"M"/"B" suffixes -> axis follows the total-level pattern; data labels per point -> override Y axis display units if the scale still looks offAI-assisted drafting: AI was used to help structure and phrase this response. I reviewed and validated the technical content before posting.
Hi powerbiexpert22,
This normally happens when the Y-axis Display units are still set to Auto.
Your dynamic format string changes how the measure is displayed, but the chart can still apply its own K/M/B scaling on top of that.
Try this first:
- Select the chart.
- Go to Format visual → Y-axis → Values.
- Set Display units = None.
- If you are also using data labels, go to Data labels → Values → Display units and set that to None as well.
Keep your actual measure numeric. For example:
Total Sales = SUM ( FactSales[SalesAmount] )
Then apply the dynamic format string separately, for example:
VAR _Value = ABS ( [Total Sales] ) RETURN SWITCH ( TRUE(), _Value >= 1000000, "#,0.0,, ""M""", _Value >= 1000, "#,0.0, ""K""", "#,0" )
This should be configured as the Dynamic format string of the measure, not as another measure using FORMAT().
The reason is that FORMAT() converts the result to text, whereas a dynamic format string keeps the measure numeric, so the Y-axis can still calculate the scale correctly.
Best Regards,
Maruthi
LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/
X - Maruthi Siva Prasad - (@MaruthiSP) / X