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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
javieregh
Frequent Visitor

Colour formatting is needed – red for negative, and green for positive in DAX

Hi 

Colour formatting is needed – red for negative, and green for positive in DAX

 

Name20192020vs LYvs LY %
A6120-41-41%
B58310%

 

I know how to do it in power bi but I need it in DAX code

Thanks
Javier
1 ACCEPTED SOLUTION

Hi @javieregh,

 

you still need to set the color measure in the "Conditional Formatting" options of the visual (as described above).

 

As @selimovd stated before, it´s not possible to do the formatting entirely in DAX. You still need to do some settings in the visual. 

 

Did this answer your question? Mark my post as a solution!

View solution in original post

6 REPLIES 6
selimovd
Super User
Super User

Hey @javieregh ,

 

the conditional formatting is part of the visual.

DAX itself will just give you the values, you cannot format in DAX, you can just use the formatting options of the visual.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

The grid is created dynamics in  DAX
 
I don't can use options visual. I would like check if dax have something that you can change the color
 
For example:
SWITCH (
SelectedMeasure,
"A", FORMAT ( Val, "Standard" ),
"B", FORMAT ( Val / 1000, "#,##0;(#,##0)" ),
)

Hi @javieregh,

 

you won´t totally get away without visual options, but you can go as far as defining the HEX-Value of a color in a Measure (so the Measure returns the HEX-Value) and then use this Measure to color the field.

 

First of all a I created a simple Measure that evaluaets if "vs LY" is positiv or negativ. For positiv it returns the hex-Value of green, for everything else it returns red:

 

color = 
var _good = "#00FF00" // green
var _bad = "#FF0000" // red
RETURN
IF([vs LY] >= 0, _good, _bad)

 

Now we can go ahead and select this Measure in the visual options under "Conditional Formatting" -> "Font Color" (or whatever you want to change) -> "Advancend Controls" (If the window doesn´t open from itself) -> Change "Format by" to "Field value" -> under "Based on field" select your previously created (in this case "color") Measure

 

Hope this helps.

 

Best regards,

 

Markus

 

Did this answer your question? Mark my post as a solution!

Thanks Markus for you email


The results print this 

Print 

javieregh_0-1617039977887.png

 

not value in color 

 

Hi @javieregh,

 

you still need to set the color measure in the "Conditional Formatting" options of the visual (as described above).

 

As @selimovd stated before, it´s not possible to do the formatting entirely in DAX. You still need to do some settings in the visual. 

 

Did this answer your question? Mark my post as a solution!

@Markus_Re @selimovd  Thanks so much Markus and Denis I saw the variable was format to Percentage I changed to standard and now working fine ... All Good 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.