Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi,
I have a measure [PO_Amount] which migh show wide range of numbers from thousands to billions. I chose dynamic format for it and entered the below in the "Format" formula bar:
Solved! Go to Solution.
Hi @AhmadBakr
The dynamic format string expression should be written to return a format string, rather than returning the formatted value itself.
For example, the format string expression should return values such as these to format billions, millions or thousands:
"0,,,.00B"
"0,,.00M"
"0,.00K"
Here is a suggested rewritten version of the format string expression:
VAR kil = 10^3
VAR mil = 10^6
VAR bil = 10^9
VAR amount = [PO_Amount]
RETURN
SWITCH(
TRUE(),
amount >= bil, "0,,,.00B",
amount >= mil, "0,,.00M",
amount >= kil, "0,.00K",
"0.00"
)
You could add "#," to the start of each string for digit grouping:
VAR kil = 10^3
VAR mil = 10^6
VAR bil = 10^9
VAR amount = [PO_Amount]
RETURN
SWITCH(
TRUE(),
amount >= bil, "#,0,,,.00B",
amount >= mil, "#,0,,.00M",
amount >= kil, "#,0,.00K",
"#,0.00"
)
Does the above work for you?
Ah right, with the Card visual (and certain other situations) make sure the visual's number format settings are not conflicting with the measure's number format.
For a Card, set
Does that fix it?
Good question 🙂
If a format string depends on a measure's value (as it does in your example), then I don't believe it's possible to assign the format string expression to a separate measure and then reference this measure within format string expressions of individual measures.
The function SELECTEDMEASURE() can be used to generically evaluate the "current" measure, but it only works when used directly in a format string expression, not in a measure referenced by a format string expression.
So the options I can suggest for applying this same format string to multiple measures are:
Hopefully that is of some help 🙂
Hi @AhmadBakr
The dynamic format string expression should be written to return a format string, rather than returning the formatted value itself.
For example, the format string expression should return values such as these to format billions, millions or thousands:
"0,,,.00B"
"0,,.00M"
"0,.00K"
Here is a suggested rewritten version of the format string expression:
VAR kil = 10^3
VAR mil = 10^6
VAR bil = 10^9
VAR amount = [PO_Amount]
RETURN
SWITCH(
TRUE(),
amount >= bil, "0,,,.00B",
amount >= mil, "0,,.00M",
amount >= kil, "0,.00K",
"0.00"
)
You could add "#," to the start of each string for digit grouping:
VAR kil = 10^3
VAR mil = 10^6
VAR bil = 10^9
VAR amount = [PO_Amount]
RETURN
SWITCH(
TRUE(),
amount >= bil, "#,0,,,.00B",
amount >= mil, "#,0,,.00M",
amount >= kil, "#,0,.00K",
"#,0.00"
)
Does the above work for you?
Hi @OwenAuger
Thank you for your response.
In fact I tried something similar and did not work.
I tried the code you suggested and for a value 17.46bn (as auto formatted), it returned 0.00bnB (!)
I am not sure what might be missing.
Ah right, with the Card visual (and certain other situations) make sure the visual's number format settings are not conflicting with the measure's number format.
For a Card, set
Does that fix it?
Thanks a lot, this solved it. I was tuning all these (code plus format) but your code together with the right format setting did the job.
Much appreciated, you save me double the number of measures to write a dedicated format measure for every numerical measure 🙂
Thank you.
Is there a way to reference a generic measure name, so I can assign the dynamic format code to a measure and use this measure name in the dynamic format string of any measure without the need to change the name of the measure to be formatted (highlighted red below)?
VAR kil = 10^3
VAR mil = 10^6
VAR bil = 10^9
VAR input = [Amt]
RETURN
SWITCH(
TRUE(),
input >= bil, "#,0,,,.00B",
input >= mil, "#,0,,.00M",
input >= kil, "#,0,.00K",
"#,0.00"
)
Good question 🙂
If a format string depends on a measure's value (as it does in your example), then I don't believe it's possible to assign the format string expression to a separate measure and then reference this measure within format string expressions of individual measures.
The function SELECTEDMEASURE() can be used to generically evaluate the "current" measure, but it only works when used directly in a format string expression, not in a measure referenced by a format string expression.
So the options I can suggest for applying this same format string to multiple measures are:
Hopefully that is of some help 🙂
The first solution appeals to me more and worked. you are right, when I assigned the format code to a separate measure and used it to format the Amt measure, didn't work, althought I tried (for the fun of it) to use VALUE() but no! May be later we can get some function like EXCEL's INDIRECT() 🙂
And thank you for the article as well. This is super useful.
Thanks a lot for your responses and support.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
11 | |
10 | |
10 | |
10 |
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
8 |