Forum Discussion

powerbiexpert22's avatar
powerbiexpert22
Icon for Impactful Individual rankImpactful Individual
16 days ago
Solved

dynamic format string causing incorrect Y scale

i have applied dynamic format string in my semantic model however the Y axis scale is showing repeated value        
  • jubinsoni's avatar
    16 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 off

    AI-assisted drafting: AI was used to help structure and phrase this response. I reviewed and validated the technical content before posting.