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,870 points
2,399 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,770 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 3, 2019 in Power BI by Avantika
• 1,520 points
2,622 views
0 votes
2 answers

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

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

answered Jun 11, 2020 in Power BI by Excel
• 140 points
7,865 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 22, 2019 in Power BI by anonymous
• 33,030 points

edited Dec 31, 2021 by Soumya 36,976 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
956 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,350 points
1,022 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,350 points
886 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,350 points
1,233 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,770 points
815 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,770 points
1,074 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP