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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
kumar27
Advocate V
Advocate V

How to write DAX to get color ,

For my symboles , i always use DAX using UNICHAR function and it gives me correct results. for e.g

Symbol=
SWITCH(TRUE(),
 SUM(financials[ Sales])>25000000, UNICHAR(9660),
 2)


But i wonder , if I can write Hexa colour codes within DAX and not do anything from conditional formatting , Is it possible ?

> I tried using Hexa codes in place of unichar above and it does not work ..

Colour =
SWITCH(TRUE(),
 SUM(financials[ Sales])>25000000, "#000000",
 2)
1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @kumar27 ,

In my opinion, it does not work directly, you still need to use the conditional format operation. First adjust your code.

Colour = 
SWITCH(TRUE(),
 SUM(financials[sales])>25000000, "#000000",
 BLANK())

Then  choose color:

vluwangmsft_0-1658911347314.pngvluwangmsft_1-1658911374874.png

As your colour code is black, the change is not visible.A little adjust.

vluwangmsft_2-1658911471580.png

Return :

vluwangmsft_3-1658911483367.png

 

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


Best Regards

Lucien

View solution in original post

4 REPLIES 4
v-luwang-msft
Community Support
Community Support

Hi @kumar27 ,

In my opinion, it does not work directly, you still need to use the conditional format operation. First adjust your code.

Colour = 
SWITCH(TRUE(),
 SUM(financials[sales])>25000000, "#000000",
 BLANK())

Then  choose color:

vluwangmsft_0-1658911347314.pngvluwangmsft_1-1658911374874.png

As your colour code is black, the change is not visible.A little adjust.

vluwangmsft_2-1658911471580.png

Return :

vluwangmsft_3-1658911483367.png

 

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


Best Regards

Lucien

ribisht17
Super User
Super User

Colour =
SWITCH(TRUE(),
 SUM(financials[ Sales])>25000000, "#000000",
 2)
 
You have given color to the true scenario likewise for the false scenario you would like to give a color but you have given 2 there, just pointing that
ribisht17
Super User
Super User

  

Revenue KPI Color = SWITCH(
     TRUE()
     ,SUM('Sales'[Revenue]) < 50000000, "#f44242"
     ,SUM('Sales'[Revenue]) < 1000000000, "#f4f142"
     ,SUM('Sales'[Revenue]) > 1000000000, "#5ff442",
     "#f44242"
)

Find more >> Controlling Conditional Formatting Using DAX (bluegranite.com)

Regards,

Ritesh

@kumar27

@ribisht17  Thanks .

 

The hexa in inverted commas , wont be cosidered as text ?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors