web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Some help with text co...
Power Apps
Answered

Some help with text color based on date

(0) ShareShare
ReportReport
Posted on by 697

Hello,

 

I've googled this and used the recommended code, and the green/red was working but not the yellow.  So I've been trying to fiddle with it and it's just not working, if someone can correct me.  I have a field (Thisitem.CatETExp) with a date.  I want it to change colors based on the comparison to today: 

 

If over 30 days = green.
If less than 30 days, but greater than 1 = yellow

If today or past due = red

 

I was trying this from google

If(
 DateDiff(ThisItem.CatETExp, Today()) <= 7,
 Color.Green,
 DateDiff(ThisItem.CatETExp, Today()) > 7 && DateDiff(ThisItem.CatETExp, Today()) <= 30,
 Color.Yellow,
 DateDiff(ThisItem.CatETExp, Today()) > 30,
 Color.Red
)

For some reason the green/red were working but it makes no sense to me, cause it looks like its saying if its due in 7 days or less its green? But the yellow was not working 😞

Categories:
  • Verified answer
    Tony_Bowes_BP Profile Picture
    280 on at

    DateDiff returns a value FROM the first date TO the second date, so DateDiff(Today(), Today()+5) is 5. Therefore the first section:

     

    DateDiff(ThisItem.CatETExp, Today()) <= 7

     

    is true for all values from CatETExp 7 days LESS than Today to all days in the future (negative values)

     

    To do the logic for below business rules, it would be better to check from today() to the stored date.

    So this logic: 

    If over 30 days = green.
    If less than 30 days, but greater than 1 = yellow

    If today or past due = red

     

    Would look something like:

     

    If(
     DateDiff(Today(), ThisItem.CatETExp) <= 0,
     Color.Red,
     And(DateDiff(Today(), ThisItem.CatETExp ) > 0,DateDiff(Today(), ThisItem.CatETExp ) <= 30),
     Color.Yellow,
     DateDiff(Today(), ThisItem.CatETExp ) > 30,
     Color.Green
    )

     

     

  • CharlesBrewer Profile Picture
    697 on at

    Thank you, appreciated!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 312

#3
Mohsin Ali Profile Picture

Mohsin Ali 252

Last 30 days Overall leaderboard