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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
vsslasd1
Helper III
Helper III

Conditional Color In Grid

Hello, 
I have a Measure configured like this, which is to return back a background color for the following conditions:
 

PER1BG =
var P1BG
IF(
MAXX(vwG_EquipmentTaskStatus,[PER1])>0 & MAXX(vwG_EquipmentTaskStatus,[PER1]) = MAXX(vwG_EquipmentTaskStatus,[PER1X]), "Green",
IF(MAXX(vwG_EquipmentTaskStatus,[PER1])>0 & MAXX(vwG_EquipmentTaskStatus,[PER1X] < MAXX(vwG_EquipmentTaskStatus,[PER1])), "Dark Blue",
"White"))
// MAXX(vwG_EquipmentTaskStatus,[PER1X]) & MAXX(vwG_EquipmentTaskStatus[PER1])>0 , "Green","Black"))

Return
P1BG


What I am trying to do in english is the following: 

IF Scheduled Qty> 0 and Scheduled Qty= Completed Quantity then green

If Scheduled Qty> 0 and Completed Qty >0 and Completed Quantity < Scheduled Quantity, Dark Blue,

White.


My syntax is not working, and in addition when I try  to change the conditional color per a value in the grid, it won't let me highlight the PER1BG column. 

 
What is the appropriate Measure syntax/formula to accomplish what I need in a Matrix ? and How am I amble to utilize that color in my grid?
 
Thank you!
 
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Try using && instead of & .  Also, you should pre-calculate your MAXX expression as variables first, so that you don't recalculate them multiple times and hurt performance.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
mahoneypat
Microsoft Employee
Microsoft Employee

Try returning your first two variables instead of the last one to troubleshoot.  Those are returning a Max value while the visual is likely showing the sum of that column.  If you replace MAXX with SUMX, it work as expected.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


mahoneypat
Microsoft Employee
Microsoft Employee

Try using && instead of & .  Also, you should pre-calculate your MAXX expression as variables first, so that you don't recalculate them multiple times and hurt performance.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


This seems to work: 

PER1BG =

var P1S= MAXX(vwG_EquipmentTaskStatus,[PER1])
var P1C =MAXX(vwG_EquipmentTaskStatus,[PER1X])
var P1R= MAXX(vwG_EquipmentTaskStatus,[PER1R])

var P1BG=
IF(
P1S>0 && P1C>0 && P1R<>0,
"Dark Blue",
 
If(P1S>0 && P1S = P1C, "Green",
"White"))
return
P1BG
 

The issue I have though, is it does not rollup with the matrix: for example the 9 and the six values should be dark blue, not green, per this code:
pbi matrix.png

PER1BG =

 

var P1S= MAXX(vwG_EquipmentTaskStatus,[PER1])
var P1C =MAXX(vwG_EquipmentTaskStatus,[PER1X])

 

var P1BG=
IF(
P1S>0 && P1S = P1C, "Green",
If(P1S>0 && P1C>0 && P1C<P1S, "Dark Blue",
"White"))
return
P1BG
 

This is a better picture... to demonstrate... the issue, and the travel and setup item should be dark blue as well. 

powerbi matrix 2.png

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.