Forum Discussion
Help with dynamic format strings
Hope somebody can point me in the right direction regarding dynamic formatting.
I have this table:
| Period | KPI Code | KPI value | Data Type |
| Jun-24 | PC008 | 2.12 | Number |
| May-24 | PC008 | 1.35 | Number |
| Apr-24 | PC008 | 1.54 | Number |
| Sep-25 | PC005 | 1 | Percentage |
| Aug-25 | PC005 | 1 | Percentage |
| Jul-25 | PC005 | 1 | Percentage |
| Jun-25 | PC005 | 1 | Percentage |
| May-25 | PC005 | 1 | Percentage |
| Apr-25 | PC005 | 0.98 | Percentage |
| Mar-25 | PC005 | 0.963 | Percentage |
| Feb-25 | PC005 | 0.94 | Percentage |
| Jan-25 | PC005 | 0.93 | Percentage |
| Dec-24 | PC005 | 1 | Percentage |
I want to format KPI value as % if Data type is 'Percentage', whole number if Data type is number and show each KPI in line charts like this:
Can this be achieved in dynamic format strings or is there a better way to go?
Thanks for any pointers!
8 Replies
- ryan_mayuSuper User
have you tried set up dynamics formatting for measures?
- Fusilier2Helper V
I've had a look at the article but I can't work out if it is possible to add in an IF statement for the format.
For example
IF(DataType = "Percentage", "0.0%",
IF(DateType = "Number", "0.0"
Or similar.
- v-tejramaCommunity Support
Hi Fusilier2 ,
You can achieve what you’re describing by using dynamic format strings for measures in Power BI. The approach is to let the format adjust automatically based on the data type in your model, so when the value represents a percentage, it displays with a % sign, and when it’s a plain number, it appears without it. To do this, first create a measure for your KPI value and then open the Measure tools pane to set up a dynamic format string using an expression. For example, you can use a DAX expression that checks the data type and switches the format accordingly, something like: if the data type is Percentage, return 0.0%; if it’s Number, return 0.0; otherwise, use a general format. Once you apply this, the same measure will automatically show the correct format for each KPI in your line chart without the need for multiple visuals or manual formatting. You can find more details in the official documentation on dynamic format strings for measures, which walks through this setup step by step.
Thank you.
- Fusilier2Helper V
Looks like what I want to do is not possible. All of my numbers are decimal when they are loaded into Power Query. The only way of determining which one's need to be displayed as a % and which as a whole number, is by referencing the 'Data type' column. There doesn't seem to be a way of using format strings that reference other columns. So, at the moment there is no solution to this. Thanks for everybodies help though.
- v-tejramaCommunity Support
Hello agian Fusilier2 ,
I'm glad you found a solution and were able to resolve the query. Thank you very much for sharing your findings here. It’s helpful for others facing a similar issue.
If you have any further queries, please don’t hesitate to reach out.
Thankyou for connecting with Microsoft Community Forum