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
GL10
New Member

PowerBI Measure for Colouring Date Ranges

Hi, I'd appreciate some help with the following measure. I'm looking to colour the date value as follows:

 

Red - Target Date has passed - Value "2"

Amber - Target Date is due withing 5 days - Value "1"

Green - Target Date is due over 5 days - Value "0"

 

The rule below works for the red, however, the amber value is only showing for todays date, rather than all dates due within 5 days.

 

GL10_0-1755855998361.png

 

I'd really appreciate any help with this.

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Days that are in the future will have a negative difference with today, try

Colour =
VAR _day =
    DATEDIFF ( MAX ( 'Sheet1'[Target Date] ), TODAY (), DAY )
RETURN
    SWITCH ( TRUE (), _day <= 0 && _day >= -5, 1, _day < -5, 0, _day > 0, 2 )

View solution in original post

5 REPLIES 5
johnt75
Super User
Super User

Days that are in the future will have a negative difference with today, try

Colour =
VAR _day =
    DATEDIFF ( MAX ( 'Sheet1'[Target Date] ), TODAY (), DAY )
RETURN
    SWITCH ( TRUE (), _day <= 0 && _day >= -5, 1, _day < -5, 0, _day > 0, 2 )

Amazing, that worked perfectly. Thank you so much for your help.

johnt75
Super User
Super User

You need to change the order in the SWITCH logic - when _day is greater than 0 and less than 5, which you want to be amber, it is still triggering the clause where _day is greater than 0 for red. Try

Colour =
VAR _day =
    DATEDIFF ( MAX ( 'Sheet1'[Target Date] ), TODAY (), DAY )
RETURN
    SWITCH ( TRUE (), _day >= 0 && _day <= 5, 1, _day < 5, 0, _day > 0, 2 )

Thank you so much for your quick response.

 

I've applied this formula which gets me slightly further, however, the amber is the wrong side of the target date. It needs to be red up to 21/08/2025, amber from 22/08/2025 (today) to 26/08/2025 and green from 27/08/2025 going forward.

 

GL10_0-1755858595936.png

 

GL10_1-1755858637287.png

 

It appears that the greater than and less than is working in the opposite direction for some reason?

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 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.

Top Solution Authors