Forum Discussion

powerbiexpert22's avatar
powerbiexpert22
Icon for Impactful Individual rankImpactful Individual
7 days ago

Data Labels and Y Axis - Dynamic Format String

i am using dynamic string for measures in my below shown bar chart, i am using below measure as example , i want to how data labels and Y axis values in thousands or millions with two decimal places , example 6,200,000 should appear as 6.20 M and 54,644 should appear as 54.64 K . I am using dynamic format string as shown below

 

6 Replies

  • In Power BI, use a Dynamic Format String for your measure:

    VAR Val = SELECTEDMEASURE()

    RETURN

    SWITCH(

    TRUE(),

    ABS(Val) >= 1000000, "0.00,, ""M""",

    ABS(Val) >= 1000, "0.00, ""K""",

    "#,##0.00"

    )

     

     

    This displays:

    - 6,200,000 → 6.20 M

    - 54,644 → 54.64 K

    Apply this through the measure’s Format → Dynamic expression.

    Note:

    Set the chart’s Y-axis Display units to None so Power BI doesn’t scale the values again. Configure data labels similarly if needed.

  • powerbiexpert22​ 

    you can try this

     

    VAR SelectedMeasure = ABS([Measure])
    
    RETURN
    
        SWITCH(
    
            TRUE(),
    
            SelectedMeasure < 1000,
    
                "#,0",
    
    
    
            SelectedMeasure < 1000000,
    
                "#,0,.0""K""",
    
    
    
            SelectedMeasure < 1000000000,
    
                "#,0,,.0""M""",
    
    
    
            "#,0,,,.0""B"""
    
        )

     

     

    pls see the attachment below

     

  • Hi powerbiexpert22​,

    I would keep the measure numeric and use a Dynamic format string instead of using FORMAT() in the measure.

    For example, if the measure is:

    Total Amount = SUM ( Sales[Amount] )

    Select the measure, go to Measure tools > Format > Dynamic, and use something like:

    VAR _Value = ABS ( [Total Amount] ) RETURN SWITCH ( TRUE (), _Value >= 1000000, "#,0.0,,M", _Value >= 1000, "#,0.0,K", "#,0" )

    The important part is the visual formatting.

    Set: Y-axis > Display units = None and: Data labels > Display units = None

    If Display units is left as Auto/Thousands/Millions, the visual can override the dynamic format string, which is normally why the data labels and Y-axis don't appear consistently.

    Best Regards,
    Maruthi
    LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/
    X            -  Maruthi Siva Prasad - (@MaruthiSP) / X

  • You can handle this directly in the Dynamic Format String by using the trailing comma trick to scale, then adding the suffix as a literal. Both the data labels and Y axis labels pick up the dynamic format per value in current Power BI versions.

    Try this as the format string expression on the measure:

     

    VAR _abs = ABS(SELECTEDMEASURE())
    RETURN
    SWITCH(
        TRUE(),
        _abs >= 1E6, "#,##0.00,, M",
        _abs >= 1E3, "#,##0.00, K",
        "#,##0.00"
    )

     

    Each trailing comma in the format string divides the number by 1,000, so 6,200,000 renders as 6.20 M and 54,644 as 54.64 K. If you also need a billions tier, add another branch with "#,##0.00,,, B" above the millions check.

     

    If this helped, please mark it as the accepted solution and give it a thumbs up.

     

    Best regards,
    Shai Karmani