cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AdamH
Post Patron
Post Patron

Change label colour based on date value

Hi All, 

 

I would like to change a label colour based on a date value, could anyone guide me please?

 

As an example, a member of staff has a review booked for the 20/1/22

20 Days & Over the date above, the label wants to be green.

Less than 20 days to go from the above date, the label wants to change orange

On the 20/1/22 and beyond, the label wants to turn red. 

 

I was experimenting with DateDiff but couldn't get it right. 

 

However If we have marked the review as being complete "Yes" then the label wants to turn to light green.
The Yes/No is a choice field. 

2022-01-17 23_36_35-Window.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @AdamH ,

That is because it is a yes/no field - I actually had a debate with myself whether to post the below first, but you described the input as "Yes", which infers Text. You are also missing a comma at the top.

With(
   {
      wDays:
      DateDiff(
         Today(),
         '6 Month NQP Review Date',
         Days
      )
   },
   If(
      ThisItem.'6 Month NQP Review Completed',
      LightGreen,
      wDays >= 20,
      Green,
      wDays >= 0,
      Orange,
      Red
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @AdamH ,

Something like this

With(
   {
      wDays:
      DateDiff(
         Today(),
         ReviewDateField,
         Days
      )
   },
   If(
      ReviewCompletedField = "Yes"
      LightGreen,
      wDays >= 20,
      Green,
      wDays >= 0,
      Orange,
      Red
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Hi @WarrenBelz 

 

I tried that but came up against some errors. 

2022-01-17 23_58_03-Window.png

Hi @AdamH ,

That is because it is a yes/no field - I actually had a debate with myself whether to post the below first, but you described the input as "Yes", which infers Text. You are also missing a comma at the top.

With(
   {
      wDays:
      DateDiff(
         Today(),
         '6 Month NQP Review Date',
         Days
      )
   },
   If(
      ThisItem.'6 Month NQP Review Completed',
      LightGreen,
      wDays >= 20,
      Green,
      wDays >= 0,
      Orange,
      Red
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

Toby124
Frequent Visitor

@AdamH , the code posted by @WarrenBelz  is correct. You are supposed to use a date-time value

AdamH
Post Patron
Post Patron

@WarrenBelz 

Thanks for that guide. I modified a little by placing .Value="Yes"

 

With(
   {
      wDays:
      DateDiff(
         Today(),
         ThisItem.'6 Month NQP Review Date',
         Days
      )
   },
   If(
      ThisItem.'6 Month NQP Review Completed?'.Value="Yes",
      LightGreen,
      wDays >= 20,
      Green,
      wDays >= 0,
      Orange,
      Red
   )
)

Hi @AdamH ,

So it was a Choice column - I actually see that now right at the bottom of your post.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,756)