Show data labels in k or M in the same column | Dynamic formatting in Power BI
If you want to be able to conditional format a number in Power BI as k for thousands and M for millions in the same column, the new Dynamic Formatting can do that for you.
Watch the tutorial on YouTube
The code
And here is the code for the formatting: (updated so it formats negative values also)
VAR salesMeasure = [Total Sales]
return
SWITCH(TRUE(),
salesMeasure-1000000000000 && salesMeasure< -1000000000, "#,,,.0B",
salesMeasure-1000000000 && salesMeasure< -1000000, "#,,.0M",
salesMeasure> -1000000 && salesMeasure< -1000,"#,.0K",
salesMeasure<1000,"0",
salesMeasure<1000000, "#,.0K",
salesMeasure<1000000000, "#,,.0M",
salesMeasure>=1000000000, "#,,,.0B")
But if you prefer the file, download it here – Community Downloads -#079
More tips and tricks on formatting data labels:
Was this helpful?
Thanks a lot, really helpful!!! I used the code but noticed a small error:
4th line under SWITCH
salesMeasure<100000,"0", (THIS SHOUL BE salesMeasure<1000,"0",)
Thanks!