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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Sajid02
Helper I
Helper I

M-Query for Date RAG Status

Hi Techies, 

i'm looking to add some custom columns to highlight Green, Amber, Red from a Date column in Power BI.

 

So basically, my date column is called "LastFilledStatus"

 

Today & Today - 7 = Green

In between before 7 days and before 14 days = Amber

Else Red 

 

Any help would be greatly appriciated. 

 

Thanks, 

4 REPLIES 4
v-heq-msft
Community Support
Community Support

Hi @Sajid02 ,
Here is my test data

vheqmsft_0-1707982594382.png
Create measure

Measure = 
SWITCH(
    TRUE(),
    DATEDIFF(SELECTEDVALUE('Table'[LastFilledStatus]),TODAY(),DAY) = 0 || DATEDIFF(SELECTEDVALUE('Table'[LastFilledStatus]),TODAY(),DAY) = 7,"Green",
    DATEDIFF(SELECTEDVALUE('Table'[LastFilledStatus]),TODAY(),DAY) > 7 && DATEDIFF(SELECTEDVALUE('Table'[LastFilledStatus]),TODAY(),DAY) < 14,"Yellow",
    DATEDIFF(SELECTEDVALUE('Table'[LastFilledStatus]),TODAY(),DAY) < 7 || DATEDIFF(SELECTEDVALUE('Table'[LastFilledStatus]),TODAY(),DAY) > 14, "Red"
    )

Apply to cell elements condition format

vheqmsft_1-1707982700007.png

Final output 

vheqmsft_2-1707982728738.png

 

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi, 

Just want to highlight that , 09/02 /2024 is coming in Red and 08/02/2024 is in Green . Ideally it should not .

I have tried using this in my case, after the code when i am going in conditional formatting , this measure column is taking as first value only. 

Tried creating a column , it is showing only Green vaue , nothing more.

Sajid02_0-1707990512425.png

Sajid02_2-1707990627148.png

 

Please let me know what to do ?

Thanks 

 

Hi @Sajid02 ,
Thank you for your reply, as you describe it, my understanding is that you are trying to create a new column to display the colors. If my understanding is correct, can you please provide sample data or pbix file and also please show your desired end result in screenshot or excel so that we can help you better.

Best regards,

Albert He

Hi @v-heq-msft 
I have put certain conditions & accordingly I need Rag Status column which i can apply in conditional formatting tab.

Sajid02_0-1708415360965.png

 





Thanks 


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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