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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MarceloDF
Helper I
Helper I

Matrix with conditional formatting does not work if I don't add the measure on the Matrix

Hi, I have this Matrix:

  Jan-23Feb-23Mar-23Apr-23
Customer1Product122  
 Product2 22 
Customer2Product33 3 

 

The numbers are simple measure Total Quantity = SUM('FactTable'[Quantity]) but I added the condition that if it is 0, show me blank().

 

What I want to do is a measure that paint the cells that have this condition:

If "This Month" is blank AND "The Previous Month" is greater than 0 AND "The previous previous month" is greater than 0.

 

I tried to do it like this but didn't work:

Color Flag = 

IF (  (  ([Total Quantity] ) ) = BLANK()
         &&   ([Total Quantity Previous Month])   > 0
        &&   ([Total Quantity Previous Previous Month]) > 0

, "1" , BLANK() )

Also, I tried with CALCULATE in each measure to give them context but does not work.
 
If I put this Color Flag measure in the Matrix, it works, so I don't know what I'm doing wrong.
 
Thank you in advance for the help.
2 REPLIES 2
MarceloDF
Helper I
Helper I

Hi @Raghava2422 

We have LAG in DAX? I don't find it.

 

How can I use LAG in the measures?

 

Thank you

Raghava2422
Regular Visitor

Hi @MarceloDF 
create two measures for "Total Quantity Previous Month" and "Total Quantity Previous Previous Month" using the 'LAG' function to get the values of the previous months:
Total Quantity Previous Month =
VAR CurrentMonth = SELECTEDVALUE('Calendar'[Date])
VAR PreviousMonth = CALCULATE(MAX('Calendar'[Date]), 'Calendar'[Date] < CurrentMonth)
RETURN
IF(ISBLANK(PreviousMonth), BLANK(), [Total Quantity])

Total Quantity Previous Previous Month =
VAR CurrentMonth = SELECTEDVALUE('Calendar'[Date])
VAR TwoMonthsAgo = CALCULATE(MAX('Calendar'[Date]), 'Calendar'[Date] < CurrentMonth - 1)
RETURN
IF(ISBLANK(TwoMonthsAgo), BLANK(), [Total Quantity])

you can create your "Color Flag" measure using these new measures and your desired logic:
Color Flag =
IF(
ISBLANK([Total Quantity]) &&
[Total Quantity Previous Month] > 0 &&
[Total Quantity Previous Previous Month] > 0,
1,
BLANK()
)

"Color Flag" measure should now correctly evaluate the condition you described. It checks if "This Month" is blank, "Total Quantity Previous Month" is greater than 0, and "Total Quantity Previous Previous Month" is greater than 0. If all these conditions are met, it returns 1; otherwise, it returns BLANK().

When you place the "Color Flag" measure in your matrix, it should highlight the cells that meet your specified criteria.











Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.