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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

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

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors