Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MarkCBB
Helper V
Helper V

DAX Conditional Number formatting

Hello there,

 

Not sure if this is possible, but I would like to create a DAX measure that toggles between Currency and Whole Number.

i.e. the user can use a slider to switch between viewing Unit sales to Value sales, I through the below would work, but it doesnt.

I have the slicer control working fine:

View Meansure = if(COUNTROWS(ViewValue)>1,[Total Units],IF(LASTNONBLANK(ViewValue[ViewValueType],0)="Units", [Total Units],CURRENCY([Total Value])))
1 ACCEPTED SOLUTION
Anonymous
Not applicable

My understanding is that if you want conditional formatting, you are stuck with Strings.  If you need to make numeric operations, keep the source information different to the display information.  I.e. you have a Calc measure that does all of the work, and can be use by other measures further down your chain.  Then have a Display measure that is simply the conditional format of your Calc.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @MarkCBB,

 

You can create a view table to store the select item, then write a measure switch the display item based on slicer.

 

Table formula:

 

View Table = UNION(ROW("Name","Currency"),ROW("Name","Whole Number")) 

Capture.PNG

 

 

Measure:

View Measure = 
var selector=IF(HASONEVALUE('View Table'[Name]),VALUES('View Table'[Name]),BLANK()) 
return
SWITCH(selector,"Currency",[Total Units],"Whole Number",CURRENCY([Total Units]))

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi @MarkCBB

If you want to show the amount with a leading $ sign, you have to replace the last part of your formula:

 

 

replace 
,CURRENCY([Total Value])
with
,FORMAT([AOV2],"$ #.##")

 

 

Hi @Anonymous,

 

I have tried to do that, but when that is in a chart visual the chart does not know how to display it as it changes the data type into string.

 

I also tried to wrap the Format in VALUE but Value was not able to convert the String into a number.

 

Any ideas?

Anonymous
Not applicable

My understanding is that if you want conditional formatting, you are stuck with Strings.  If you need to make numeric operations, keep the source information different to the display information.  I.e. you have a Calc measure that does all of the work, and can be use by other measures further down your chain.  Then have a Display measure that is simply the conditional format of your Calc.

Hi @Anonymous, 

 

Fair enough I had a feeling it was not going to be possible, I think the best thing I can do in this scenario is to create a "Banner" (Text Card), that says "You are viewing Units" and use SWITCH to change to "You are viewing Value" - This I can do.

 

Regards,

Mark Blackburn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.