Forum Discussion
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
- v-saisrao-msft
Community Support
Hi powerbiexpert22,
Checking in to see if your issue has been resolved. let us know if you still need any assistance.
Thank you.
- v-saisrao-msft
Community Support
Hi powerbiexpert22,
Have you had a chance to review the solution we shared by Shai_Karmani maruthisp ryan_mayu DaniyalKhaleel1 ? If the issue persists, feel free to reply so we can help further.
Thank you.
- DaniyalKhaleel1
Resolver II
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.
- ryan_mayu
Super User
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
- maruthisp
Super User
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 - Shai_Karmani
Super User
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