Forum Discussion

Fusilier2's avatar
Fusilier2
Helper V
9 months ago

Help with dynamic format strings

Hope somebody can point me in the right direction regarding dynamic formatting.

I have this table:

 

PeriodKPI CodeKPI valueData Type
    
Jun-24PC0082.12Number
    
May-24PC0081.35Number
    
Apr-24PC0081.54Number
    
Sep-25PC0051Percentage
    
Aug-25PC0051Percentage
    
Jul-25PC0051Percentage
    
Jun-25PC0051Percentage
    
May-25PC0051Percentage
    
Apr-25PC0050.98Percentage
    
Mar-25PC0050.963Percentage
    
Feb-25PC0050.94Percentage
    
Jan-25PC0050.93Percentage
    
Dec-24PC0051Percentage

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

    • Fusilier2's avatar
      Fusilier2
      Helper 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-tejrama's avatar
        v-tejrama
        Community 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.

         

  • 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-tejrama's avatar
      v-tejrama
      Community 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