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 Formatting for Dates

Hi, 

 

I have a table with a column of dates that I want to format based on when the date is. If the date is more than 2 weeks away I want it to be green, if it is is within 2 weeks of today I want it to be yellow, and if it is today or past today I want it to be red. It is a calculated column based on the date someone enrolled, and the entire table is a calculated table For instance the column that says 45 days - if the date is 12/15 I want it to be green, if the date is 11/9 I want it to be yellow, and if the date is 5/30 I want it to be red. Can someone help me do this? 

RavenJadeAK_0-1667514845481.png

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download PBIX file with the example below 

 

Create a measure like this to determine the color for each date

 

CF = 

VAR _today = TODAY()

RETURN

SWITCH( TRUE(),

    SELECTEDVALUE('DataTable'[45 Days]) > _today + 14, "#0F0", 
    
    SELECTEDVALUE('DataTable'[45 Days]) > _today, "#FF0", 

    "#F00"
)

 

 

 

Then add a Conditional Formatting rule to the 45 days column and apply the CF rule just created

cfdate1.png

 

cfdate2.png

 

 

Here are the settings for the conditional formatting

cfdate3.png

 

Giving this

cfdate4.png

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

3 REPLIES 3
MahyarTF
Memorable Member
Memorable Member

Hi,

I usually create another column and fixed the color code in that, then use it in my visual for Conditional Formatting :

DateDiffColor = if (DATEDIFF(Sheet248[Date1], Sheet248[Date2], DAY) >= 14, "#6bec58",
                    if (DATEDIFF(Sheet248[Date1], Sheet248[Date2], DAY) < 15 &&
                            DATEDIFF(Sheet248[Date1], Sheet248[Date2], DAY) > 1,
                        "#Cfe008",
                        "#E60324"
                       )
                   )
MahyarTF_0-1667518396656.png

 

Appreciate your Kudos and please mark it as a solution if it helps you

Mahyartf
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download PBIX file with the example below 

 

Create a measure like this to determine the color for each date

 

CF = 

VAR _today = TODAY()

RETURN

SWITCH( TRUE(),

    SELECTEDVALUE('DataTable'[45 Days]) > _today + 14, "#0F0", 
    
    SELECTEDVALUE('DataTable'[45 Days]) > _today, "#FF0", 

    "#F00"
)

 

 

 

Then add a Conditional Formatting rule to the 45 days column and apply the CF rule just created

cfdate1.png

 

cfdate2.png

 

 

Here are the settings for the conditional formatting

cfdate3.png

 

Giving this

cfdate4.png

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

This is perfect!! Thank you!!

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.