Forum Discussion

Reetz's avatar
Reetz
Icon for Helper II rankHelper II
6 years ago

Conditional formatting not working in a matrix

Hi All.  I have a matrix that shows Sales by month.  Dates are in the Columns and Product sales in the rows.  Our sales are always a couple of months behind so the most current month we have available is Jul'20.  I want to compare only July sales to June sales (current month to prior month).  If the current month is less than the prior month, I want to color just the current month's background red, otherwise, leave the background color as is and don't color any other cells in the row. 

 

In the example below, the first row would have no color in July since June and July are both blank.  In the 2nd row, the 4000 in July should be colored since it is less than the June sales.

  I've created the following measure to color code the cell:

 

m_Format Curr month =
VAR PriorMonthSales = CALCULATE( [Sales] , PARALLELPERIOD('Date'[Date],-1,MONTH ) )
VAR Compare = IF ( ISBLANK( PriorMonthSales ), BLANK(), [sales] - PriorMonthSales)
RETURN
SWITCH (
TRUE(),
Compare = 0, "none",
Compare < 0, "#ff7f7f",
Compare > 0, "none")
 
I tried conditional formatting the background by using the  Format by Field value but it won't let me add the measure in the Based on Field box.  I think it's because it is a measure.  What am I doing wrong?
 
Thanks in advance for your help!!

2 Replies