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 / Background Fill Colour...
Power Apps
Unanswered

Background Fill Colour based on dates

(0) ShareShare
ReportReport
Posted on by 127

Hi,

I am trying to fill the background colour of a gallery based on several different dates, or based on text if no date is required.

My date label has the following code: 

If(IsBlank(Text(ThisItem.ExpiryDate)), "Expiry - N/A", "Expiry - " & " " & 
Text(ThisItem.ExpiryDate, DateTimeFormat.LongDate))

I have got this working fine for the dates, but when the text is "Expiry - N/A", I can't get it to change to green which is the colour I would like for this specific text. Here is the code I have for the Gallery Fill property:

If(
 //Check if it is later than 2 months from today
 ThisItem.ExpiryDate > DateAdd(
 Today(),
 2,
 Months
 ),
 RGBA(//Green
 14,
 209,
 69,
 0.2
 ),
 If(
 //Check if it is today or older
 ThisItem.ExpiryDate <= Today(),
 RGBA(//Red
 255,
 0,
 0,
 0.2
 ),
 
 //Anything else
 RGBA(// Orange
 255,
 191,
 0,
 0.2
 )
 )
 )

I have tried adding another If statement but could not get it to work, I also tried a Switch statement but that did not work either. I am guessing it is because the text is not a date. Here is a screenshot of what I have so far, the red should be green as it says "Expiry - N/A".

VictorTek_0-1677530026846.png

Can any one help with this please

Thanks in advance

Categories:
I have the same question (0)
  • TheRobRush Profile Picture
    11,128 Moderator on at

    try this, think it's right but typed in a notepad so may be missing a piece of punctuation, nbut oitherwise should be correct

    Switch( 
    
    IsBlank(Text(ThisItem.ExpiryDate)),
    
    true, RGBA(//Green
     14,
     209,
     69,
     0.2
     ),
    
    If(
     //Check if it is later than 2 months from today
     ThisItem.ExpiryDate > DateAdd(
     Today(),
     2,
     Months
     ),
     RGBA(//Green
     14,
     209,
     69,
     0.2
     ),
     If(
     //Check if it is today or older
     ThisItem.ExpiryDate <= Today(),
     RGBA(//Red
     255,
     0,
     0,
     0.2
     ),
     
     //Anything else
     RGBA(// Orange
     255,
     191,
     0,
     0.2
     )
     )
     )
    )

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,074

#2
Valantis Profile Picture

Valantis 639

#3
11manish Profile Picture

11manish 606

Last 30 days Overall leaderboard