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
Anonymous
Not applicable

Conditional Color Formatting based on date

Hi,

 

I have the following visualization using Matrix:

 

image.png

 

How do I color the background of the values under date for each dates if changed. Say first row data shows: the value changed from '4' to '5' for dates 09/19/2019 & 09/20/2019, 09/23/2019.

 

I want to change the background colors only if it has changed the values, otherwise should remain in same color for future results.

 

Thanks

 

1 ACCEPTED SOLUTION

HI, @Anonymous 

The problem is that you are using SUM [Date] in the formula:

1.JPG

 

After my research on your sample pbix file, [Index] is text column, so you could try this formula:

Conditional = 
VAR _lastdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < MAX ( 'Table'[Date] ) )
    )
RETURN
    IF (
        _lastdate <> BLANK (),
        IF (
            CALCULATE (MAX(  'Table'[Index] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( MAX( 'Table'[Index] ) ) = 0,  1,  2),
        1
    )

Result:

2.JPG

By the way, you could also adjust the formula as below so that if the value increase it will be red and if the value decrease it will be green.

Measure 2 = VAR _lastdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < MAX ( 'Table'[Date] ) )
    )
RETURN
    IF (
        _lastdate <> BLANK (),
        IF (
            CALCULATE (MAX(  'Table'[Index] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( MAX( 'Table'[Index] ) )  <0,  3,  IF (
            CALCULATE (MAX(  'Table'[Index] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( MAX( 'Table'[Index] ) ) >0,2,
        1
    )),1)

3.JPG

Result:

4.JPG

and here is sample pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

For your case, just create a measure for conditional formatting as below:

Conditional = 
VAR _lastdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < MAX ( 'Table'[Date] ) )
    )
RETURN
    IF (
        _lastdate <> BLANK (),
        IF (
            CALCULATE (SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( SUM ( 'Table'[Value] ) ) = 0,  1,  2),
        1
    )

Then create the condtional formatting as below:

11.JPG

Result:

12.JPG

here is sample pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

image.pngHi @v-lili6-msft ,

Thanks for your solution. Can you please help me on this?

It seems to be highlighting every first occurences of the values for search_terms. Please find the screenshot: 

 

What I actually want is to to change the color only if the value has changed. For example:

 

image.png

 

Here the value of certain dates has changed from '3' to '4'. It has increased so it should be of different color(Red - Warning). If it remains same for next date, shouldn't change at all or no color. If it has decreased then it should be in different color(Green - Acceptable). I want to see the values of each search_terms is actually improving with numbers reducing for each dates or consistent. 

 

I hope I'm clear. 

 

Thanks

 

 

 

 

 

HI, @Anonymous 

The problem is that you are using SUM [Date] in the formula:

1.JPG

 

After my research on your sample pbix file, [Index] is text column, so you could try this formula:

Conditional = 
VAR _lastdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < MAX ( 'Table'[Date] ) )
    )
RETURN
    IF (
        _lastdate <> BLANK (),
        IF (
            CALCULATE (MAX(  'Table'[Index] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( MAX( 'Table'[Index] ) ) = 0,  1,  2),
        1
    )

Result:

2.JPG

By the way, you could also adjust the formula as below so that if the value increase it will be red and if the value decrease it will be green.

Measure 2 = VAR _lastdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] < MAX ( 'Table'[Date] ) )
    )
RETURN
    IF (
        _lastdate <> BLANK (),
        IF (
            CALCULATE (MAX(  'Table'[Index] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( MAX( 'Table'[Index] ) )  <0,  3,  IF (
            CALCULATE (MAX(  'Table'[Index] ), FILTER ( ALLSELECTED ( 'Table'[Date] ), 'Table'[Date] = _lastdate )) - CALCULATE ( MAX( 'Table'[Index] ) ) >0,2,
        1
    )),1)

3.JPG

Result:

4.JPG

and here is sample pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hi, @Anonymous 

Could you share your sample pbix file for me have a test? There should be something wrong in other.

You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.