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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
AMBP1973
Helper II
Helper II

Dax for Dates RAG Status

Hello Everyone,

I am looking to add conditional formatting to a date column to highlight due dates using Red, Abber and Green. 

 

My date column is called 'Cancellation Date'. I would like to highlight dates as follows:

 

Anything due before today = Red

Anything due in the next 6 months = Amber

Anything due in more than 6 months = Green

 

Any assistance would be much appreciated.

 

 

1 ACCEPTED SOLUTION

hi, @AMBP1973 

try below code 

output =
var a = DATEDIFF(TODAY(),MAX('rag'[date]),MONTH)
var b =
SWITCH(TRUE(),
a<=0,"#FF0000",
a<=6&& a>0,"#FFBF00",
a>6,"#00FF00"
)
return
b
 
Here you get only red and green combination becuase in your data which you provide none of date lies bw 0 to 6 month .
i already calculate measurte which indicate difference bw today and due date 

Dangar332_1-1697521063161.png

 

 
Dangar332_0-1697520865798.png

 

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos

View solution in original post

9 REPLIES 9
Dangar332
Super User
Super User

hi , @AMBP1973 

 

try below Dax code  and adjust your table and column name
output = 

var a = DATEDIFF(TODAY(),MAX('Table'[Column1]),MONTH)
return
SWITCH(TRUE(),
a=0,"#FF0000",
a<=6,"#FFBF00",
a>6,"#00FF00"
)
follow below step
Dangar332_0-1697273190272.png

 

chane gradient to field value

Dangar332_2-1697273282187.png

choose your measure name and press ok.

you get your result.

Dangar332_3-1697273392943.png

 

refer  Here  to download pbix. file of your requirnment.
 
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos.

@Dangar332 This is amazing, thankyou so much. It is mainly working well except the dates before today are highlighting yellow instead of red? Any suggestions please?

hi, @AMBP1973 

 

check below it's correct  compare today date . i mention today date(to) in image 

Dangar332_0-1697518110681.png

if you still not get your answer provide some data

 

Hi @Dangar332 , I have checked the DAX I input and it is exactly as you have stated. Here is a snapshot of the cancellation date colomun. Thankyou for your ongoing assistance. 

 

AMBP1973_0-1697519057379.png

 

hi, @AMBP1973 

try below code 

output =
var a = DATEDIFF(TODAY(),MAX('rag'[date]),MONTH)
var b =
SWITCH(TRUE(),
a<=0,"#FF0000",
a<=6&& a>0,"#FFBF00",
a>6,"#00FF00"
)
return
b
 
Here you get only red and green combination becuase in your data which you provide none of date lies bw 0 to 6 month .
i already calculate measurte which indicate difference bw today and due date 

Dangar332_1-1697521063161.png

 

 
Dangar332_0-1697520865798.png

 

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos

Amazing. Thankyou @Dangar332 , really appreciate your assistance 🙂

is this solution or still not get answer ?

Dangar332
Super User
Super User

hi, @AMBP1973 

please refer Here 

you get idea how to do conditional formatting using DAX.

if still not get idea provide some data

Hi @Dangar332 . I just thought this could be acheived as I have seen it in a simular question before, but it wasn't quite what I was after. As listed in my question this would be based on a date column called 'Cancellation Date'. I would like to highlight dates as follows:

 

Anything due before today = Red

Anything due in the next 6 months = Amber

Anything due in more than 6 months = Green

 

Thankyou in advance

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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