Forum Discussion

pp_123's avatar
pp_123
New Member
1 year ago
Solved

issue with dynamic formatting

Hi I am facing an issue with dynamic formatting.
The dynamic formatting code is shown below:

var _currentvalue = SUM('Sales By Product Details'[Sale])
var _numberformat =
 SWITCH (
    TRUE(),
    _currentvalue <= 1E3, "#,0.",
    _currentvalue <= 1E4, "#,0,.00 K",
    _currentvalue <= 1E5, "#,0,.0 K",
    _currentvalue <= 1E6, "#,0,. K",
    _currentvalue <= 1E7, "#,0,,.00 M",
    _currentvalue <= 1E8, "#,0,,.0 M",
    _currentvalue <= 1E9, "#,0,,. M"
 )
 RETURN _numberformat

 

Result:

the formating in the table looks fine as shown in screenshot below:


however, the formatting on the bar graph is completely out of place as shown below:

Any help will be highly appreciated!

Thank you!

  • Thanks for confirming those steps — sounds like you're doing everything right on the surface. Since the dynamic format still isn't applying in the visual, here are a few deeper checks you can try:

    1. Double-check the measure assignment

    Make sure the dynamic format string is assigned to the same measure that’s being used in the visual. Sometimes a copy or renamed version of the measure is used in the chart, and the formatting doesn’t carry over.

    2. Use FORMAT function as a fallback

    If the visual still ignores the format string, you can try formatting the value manually in a new measure:

    Formatted Value = 
    VAR _value = [YourMeasure]
    VAR _format = 
        SWITCH (
            TRUE(),
            _value < 1E3, "#,0",
            _value < 1E6, "#,0.0,K",
            _value < 1E9, "#,0.0,,M",
            "#,0,,B"
        )
    RETURN FORMAT(_value, _format)

    Then use this Formatted Value in a card or table visual to test if the formatting logic works as expected.

    ⚠️Note: This won't work in bar/column charts directly since they expect numeric values — but it's a good way to debug the format logic.

    3. Try a clean test visual

    Sometimes visuals cache formatting. Try:

    • Creating a new bar chart from scratch.
    • Drag the measure again.
    • Set display units to None.
    • Recheck if the dynamic format kicks in.

    4. Known limitation

    Dynamic format strings don’t always apply to data labels in visuals like bar/column charts — especially if the visual is using auto-scaling or display units. In that case, it might be a current limitation of the visual engine.
    translation and formatting supported by AI

6 Replies

  • Hi pp_123 ,

     

    Dynamic formatting often works well in tables and matrix visuals, but can behave unexpectedly in bar or column charts – especially with complex format strings like "#,,00.,M".

    Here’s what you can try:

    1. Simplify your format strings to something like:
       SWITCH (
           TRUE(),
           _currentvalue < 1E3, "#,0",
           _currentvalue < 1E6, "#,0.0,K",
           _currentvalue < 1E9, "#,0.0,,M",
           "#,0.0,,B"
       )
    1. If you're using dynamic format strings in a measure, make sure to assign the format string in the Model view under “Format string expression”.

    2. Alternatively, for bar charts, try setting the data label display units manually (e.g., Thousands or Millions) in the formatting pane.

     

    If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
    translation and formatting supported by AI

    • pp_123's avatar
      pp_123
      New Member

      burakkaragoz 
      Thank you for the prompt response!
      1. I am using it for a measure and have also assigned it under "Format string expression".
      2. Display units have been set as "None".
      Still doesn't solve the issue. 

      • burakkaragoz's avatar
        burakkaragoz
        Super User

        Thanks for confirming those steps — sounds like you're doing everything right on the surface. Since the dynamic format still isn't applying in the visual, here are a few deeper checks you can try:

        1. Double-check the measure assignment

        Make sure the dynamic format string is assigned to the same measure that’s being used in the visual. Sometimes a copy or renamed version of the measure is used in the chart, and the formatting doesn’t carry over.

        2. Use FORMAT function as a fallback

        If the visual still ignores the format string, you can try formatting the value manually in a new measure:

        Formatted Value = 
        VAR _value = [YourMeasure]
        VAR _format = 
            SWITCH (
                TRUE(),
                _value < 1E3, "#,0",
                _value < 1E6, "#,0.0,K",
                _value < 1E9, "#,0.0,,M",
                "#,0,,B"
            )
        RETURN FORMAT(_value, _format)

        Then use this Formatted Value in a card or table visual to test if the formatting logic works as expected.

        ⚠️Note: This won't work in bar/column charts directly since they expect numeric values — but it's a good way to debug the format logic.

        3. Try a clean test visual

        Sometimes visuals cache formatting. Try:

        • Creating a new bar chart from scratch.
        • Drag the measure again.
        • Set display units to None.
        • Recheck if the dynamic format kicks in.

        4. Known limitation

        Dynamic format strings don’t always apply to data labels in visuals like bar/column charts — especially if the visual is using auto-scaling or display units. In that case, it might be a current limitation of the visual engine.
        translation and formatting supported by AI

  • Hi pp_123 ,

     

    The issue is caused by Power BI’s visual-level auto-scaling adding units like “K” or “M” on top of your dynamic DAX formatting, which also includes “K” or “M”. This results in labels like “0.0KK” or “0.0KM”. Although your formatting works correctly in a table visual, bar or column charts apply their own unit scaling unless explicitly told not to. To fix this, go to the visual where the labels are incorrect, then under the format pane, find the axis or data label settings and set the “Display units” to “None” instead of “Auto”. This disables Power BI’s automatic abbreviation and lets your custom DAX format take full control.

    You can also simplify and future-proof your dynamic format string like this:

    VAR _currentvalue = SUM('Sales By Product Details'[Sale])
    RETURN
        SWITCH(
            TRUE(),
            _currentvalue < 1E3, "#,0",
            _currentvalue < 1E6, "#,0,.0 K",
            _currentvalue < 1E9, "#,0,,.0 M",
            "#,0,,,.0 B"
        )
    

    This avoids overlapping format definitions and makes it easier to read and debug.

     

    Best regards,

    • pp_123's avatar
      pp_123
      New Member

      Hi DataNinja777 ,
      Thank you for replying so promptly! Unfortunately, changing the display units to "None" didn't work. Additionally I tried it with your code as well. No luck!