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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Power Query Formula's for Dates RAG Status

Hello i'm looking to add some custom collumns to highlight Red, Amber,Yellow & White from a Date collum in Power BI.

 

So basically, my date collumn is called "Fix Target"

 

Anything Before today = Red

Anything Today = Amber

Tomorrow = Yellow

After tomorrow = White

 

Any help would be greatly appriciated. 

 

Thanks, 

1 ACCEPTED SOLUTION
mahenkj2
Solution Sage
Solution Sage

Hi @Anonymous ,

Incase you would like to add custom column, one way is as below:

 

mahenkj2_0-1653606899815.png

 

Output is as below:

mahenkj2_1-1653606959056.png

 

Formulae I used:

if [Fix Target]=Date.From(DateTime.LocalNow()) then "Amber" else if [Fix Target]=Date.AddDays(Date.From(DateTime.LocalNow()),1) then "Yellow" else if [Fix Target]>Date.AddDays(Date.From(DateTime.LocalNow()),1) then "White" else "Red"

 

Just ensure proper functionality.

 

If you intended color formatting to your date column, just use this custom column in formatting logic.

 

Hope it helps.

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Sorry this just shows my column as an error? Capture4.JPGCapture5.JPG

Hi @Anonymous ,

 

Oh I see another message from you. Please click on Error cell, you should be able to see the error description, try to resolve that or please ask here. Additionally, check about your date column, does it contain null or error, if yes, can you remove that?

Else in your current formula need to give a check for null dates. First pls check and confirm in detail.

 

mahenkj2
Solution Sage
Solution Sage

Hi @Anonymous ,

Incase you would like to add custom column, one way is as below:

 

mahenkj2_0-1653606899815.png

 

Output is as below:

mahenkj2_1-1653606959056.png

 

Formulae I used:

if [Fix Target]=Date.From(DateTime.LocalNow()) then "Amber" else if [Fix Target]=Date.AddDays(Date.From(DateTime.LocalNow()),1) then "Yellow" else if [Fix Target]>Date.AddDays(Date.From(DateTime.LocalNow()),1) then "White" else "Red"

 

Just ensure proper functionality.

 

If you intended color formatting to your date column, just use this custom column in formatting logic.

 

Hope it helps.

We also have one condition in which we need to show the date column as Red Amber Green for dates which are older than 7days from Today as green , older than -8 days but less than 14 days as Amber and rest all dates as Red , How can we achive this ?

When using DAX as below it not showing the results correctly = 

IF(MAX('DW Celoxis_TimeEntries'[data']][0]]['date]) >= TODAY() -7 , "Green" ,
IF(MAX('DW Celoxis_TimeEntries'[data']][0]]['date])< TODAY() -7 && MAX('DW Celoxis_TimeEntries'[data']][0]]['date])>= TODAY() -14 , "Yellow" , "Red")).
 
Can anyone help on this ?
Anonymous
Not applicable

Hello, Thank you for replying, i seem to be having an error come up when i try to complete this as above? Please see below. 

 

=IF [Fix Target] = Date.From(DateTime.LocalNow()) then "Amber" else if [Fix Target]=Date.AddDays(date.from(DateTime.LocalNow()),1) then "YELLOW" else if [Fix Target]>Date.AddDays(date.from(DateTime.LocalNow()),1) then "White" else "Red"

Capture-.JPG

Hi @Anonymous ,

 

Power query (M) is case sensitive, so please use proper syntax, like Date.From is written as date.from in your formula which is not correct. Auto correct should help you. Else you may also please go on Mincorsoft documentation for Power query.

 

The correct syntax for the formula you shown above is:

if [Fix Target] = Date.From(DateTime.LocalNow()) then "Amber" else if [Fix Target]=Date.AddDays(Date.From(DateTime.LocalNow()),1) then "YELLOW" else if [Fix Target]>Date.AddDays(Date.From(DateTime.LocalNow()),1) then "White" else "Red"

 

Hope it helps.

Anonymous
Not applicable

Sorry, i'm still getting errors? Not sure why? Capture6.JPG

Pls share sample file with no sensitive data!

Anonymous
Not applicable

Capture.JPG

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors