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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dhrupal_shah
Helper I
Helper I

Conditional formatting not applied

Dear All,

 

created matrix visual from sql data which contain more than 20 column. i want to conditional fomatting on column name based. please refer my below code  and screen shot. as per condition given but output is comes only in red color. please help me to short it out.

 

Thanking you,

Dhrupal shah

 

Production_Color =
SWITCH(
TRUE(),
TRIM('Production'[ComponentName]) = "CTL 1" && 'Production'[QtyRecv] > 50 , "#008000", // Green
TRIM('Production'[ComponentName]) = "CTL 1" && 'Production'[QtyRecv] >=35 && 'Production'[QtyRecv] <= 50, "#000a00", // Black
TRIM('Production'[ComponentName]) = "CTL 1" && 'Production'[QtyRecv] > 0 && 'Production'[QtyRecv] < 35, "#FF0000" //Red
)

 

dhrupal_shah_0-1730720525569.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @dhrupal_shah ,

 

You can try the following measure.

 

Measure = 
VAR _sum = SUM('Production'[QtyRecv])
RETURN
SWITCH(
TRUE(),
TRIM(MAX('Production'[ComponentName])) = "CTL 1" && _sum > 50 , "#008000", // Green
TRIM(MAX('Production'[ComponentName])) = "CTL 1" && _sum >=35 && _sum <= 50, "#000a00", // Black
TRIM(MAX('Production'[ComponentName])) = "CTL 1" && _sum > 0 && _sum < 35, "#FF0000" //Red
)

 

vkaiyuemsft_1-1731315286700.png

 

vkaiyuemsft_0-1731315261533.png

Also, depending on whether you want all columns to have conditional formatting added to them? If so, just remove the condition “TRIM(MAX(‘Production’[ComponentName])) = ‘CTL 1’”

 

More detailed information can be found in the attachment.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @dhrupal_shah ,

 

You can try the following measure.

 

Measure = 
VAR _sum = SUM('Production'[QtyRecv])
RETURN
SWITCH(
TRUE(),
TRIM(MAX('Production'[ComponentName])) = "CTL 1" && _sum > 50 , "#008000", // Green
TRIM(MAX('Production'[ComponentName])) = "CTL 1" && _sum >=35 && _sum <= 50, "#000a00", // Black
TRIM(MAX('Production'[ComponentName])) = "CTL 1" && _sum > 0 && _sum < 35, "#FF0000" //Red
)

 

vkaiyuemsft_1-1731315286700.png

 

vkaiyuemsft_0-1731315261533.png

Also, depending on whether you want all columns to have conditional formatting added to them? If so, just remove the condition “TRIM(MAX(‘Production’[ComponentName])) = ‘CTL 1’”

 

More detailed information can be found in the attachment.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

Anonymous
Not applicable

Hi @dhrupal_shah ,

 

You can try the following expression.

Column = 
VAR _sum = CALCULATE(SUM(Production[QtyRecv]),FILTER('Production','Production'[DocumentDate] = EARLIER(Production[DocumentDate]) && TRIM('Production'[ComponentName]) = "CTL 1"))
RETURN
SWITCH(
TRUE(),
TRIM('Production'[ComponentName]) = "CTL 1" && _sum > 50 , "#008000", // Green
TRIM('Production'[ComponentName]) = "CTL 1" && _sum >=35 && _sum <= 50, "#000a00", // Black
TRIM('Production'[ComponentName]) = "CTL 1" && _sum > 0 && _sum < 35, "#FF0000" //Red
)

vkaiyuemsft_0-1731306493831.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

Dear Clara,

 

this is not workable you can see in below screenshot, also it is hardcore for CTL 1. we achive it with adding one new column and it work fine.

dhrupal_shah_0-1731311111962.png

 

thanks for your support.

Anonymous
Not applicable

Hi @dhrupal_shah ,

 

Based on your description, your Production_Color should be a calculated column and when it is put into a conditional format, the aggregation method can only be First or Last.

vkaiyuemsft_0-1730775547796.png

 

Whereas your QtyRecv field can have multiple aggregation methods in the matrix.

vkaiyuemsft_1-1730775557337.png

 

Therefore, you need to write the calculated column with the same aggregation method as in the matrix. I wrote this using sum as an example:

Production_Color = 
VAR _sum = CALCULATE(SUM(Production[QtyRecv]),FILTER('Production','Production'[DocumentDate] = EARLIER(Production[DocumentDate]) && 'Production'[ComponentName] = EARLIER(Production[ComponentName])))
RETURN
SWITCH(
TRUE(),
TRIM('Production'[ComponentName]) = "CTL 1" && _sum > 50 , "#008000", // Green
TRIM('Production'[ComponentName]) = "CTL 1" && _sum >=35 && _sum <= 50, "#000a00", // Black
TRIM('Production'[ComponentName]) = "CTL 1" && _sum > 0 && _sum < 35, "#FF0000" //Red
)

vkaiyuemsft_2-1730775581342.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

thanks for your solution. 

not get result as expected. even 48.17 it show green.

Screenshot 2024-11-07.png

Anonymous
Not applicable

Hi @dhrupal_shah ,

 

Can you share sample data in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

Dear Clara,

please find download link of xls

https://we.tl/t-Wt7XYfNOk4

Best Regards,

Dhrupal Shah

 

 

dhrupal_shah_0-1731064172982.png

 

PhilipTreacy
Super User
Super User

Hi @dhrupal_shah 

 

Download PBIX file with the example below

 

You don't need to name the column in the measure, you apply the measure to the column as conditional formatting using this DAX

 

 

Production_Color = 

VAR _QtyRecv = SELECTEDVALUE(Production[QtyRecv])

RETURN

SWITCH(

TRUE(),

_QtyRecv > 50 , "#008000", // Green

_QtyRecv >=35 && _QtyRecv <= 50, "#000a00", // Black

_QtyRecv > 0 && _QtyRecv < 35, "#FF0000" //Red

)

 

 

 

PhilipTreacy_0-1730763881330.png

 

PhilipTreacy_1-1730763905555.png

 

 

PhilipTreacy_2-1730763924268.png

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.