How to use Dynamic DAX Number Format in power BI

0 votes

I want to dynamically change the number format of a DAX measure, based on a dimension value.

Here's an example of the type of measure I'm creating:

My Measure:=IF ( 
    HASONEVALUE ( dimMeasureType[Measure Type] ), 
    SWITCH ( VALUES ( dimMeasureType[Measure Type] ),
        "Total Cost", FORMAT ( [Total Cost], "#,##0, k" ),
        "Cost Per Unit", FORMAT ( [Cost Per Unit], "#,##0.00" ),
        "Cost % Sales", FORMAT ( [Cost % Sales], "0.00%" ),
        BLANK()
    ),
    BLANK()
)

Is there another technique for dynamically changing a measure number format, without converting to a string?

Dec 8, 2020 in Power BI by Rajiv
• 8,880 points
310 views

1 answer to this question.

0 votes

You can give them the same display name by adding whitespace to the end of their names:

My Measure:=IF ( 
    SELECTEDVALUE( dimMeasureType[Measure Type] ) = "Total Cost", 
    [Total Cost],
    BLANK()
)
[My Measure ]:=IF ( 
    SELECTEDVALUE( dimMeasureType[Measure Type] ) = "Cost Per Unit", 
    [Cost Per Unit],
    BLANK()
)
[My Measure  ]:=IF ( 
    SELECTEDVALUE( dimMeasureType[Measure Type] ) = "Cost % Sales", 
    [Cost % Sales],
    BLANK()
)

This has some drawbacks though:

  • The chart legend shows all measures, even if all their values are BLANK().
  • The y-Axis of your chart has the same format as the first measure in its 'Values' section.
answered Dec 8, 2020 by Gitika
• 65,870 points

Related Questions In Power BI

0 votes
1 answer

How To use R Integration in Power BI?

Hi,  There are a lot of packages available ...READ MORE

answered May 2, 2019 in Power BI by avantika
• 1,500 points
1,048 views
0 votes
2 answers

How to format negative numbers in red parenthesis in Power BI Desktop?

Hi Phalguni,  Thanks for your question. It used ...READ MORE

answered Jun 10, 2020 in Power BI by Excel
• 140 points
4,334 views
0 votes
1 answer

How to rename a column using DAX in Power BI?

Hi Ramya, I found these two function that ...READ MORE

answered Aug 21, 2019 in Power BI by anonymous
• 32,930 points
8,952 views
0 votes
1 answer

How to use a gateway in Power Bi?

Follow the below procedure - 1. Install ...READ MORE

answered Oct 29, 2019 in Power BI by rachael
193 views
0 votes
1 answer

Install Power BI Desktop

It’s a pretty simple process. All you ...READ MORE

answered Oct 9, 2018 in Power BI by Kalgi
• 52,310 points
236 views
0 votes
1 answer

Few tips before I start creating Power BI dashboard

It’s always advisable to begin with the data ...READ MORE

answered Oct 9, 2018 in Power BI by Kalgi
• 52,310 points
191 views
0 votes
1 answer

How do I format the KPI in Power BI

format the KPI by selecting the paint ...READ MORE

answered Oct 9, 2018 in Power BI by Kalgi
• 52,310 points
244 views
+1 vote
1 answer
0 votes
1 answer

How to use No QUARTER() in DAX in power BI?

One should use =ROUNDUP(MONTH([Date])/3, 0) to get quarte ...READ MORE

answered Dec 8, 2020 in Power BI by Gitika
• 65,870 points
60 views
0 votes
1 answer

How to Create and use doughnut charts in Power BI?

Hey, To create a doughnut chart in Power ...READ MORE

answered Feb 6, 2020 in Power BI by Gitika
• 65,870 points
265 views