cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JL6
Helper I
Helper I

changing colour of button based on date

Hi all, 

 

I have a button that takes me to a gallery if an item is out of date.  I want to change the colour of the button if there is an out of date item versus no item but I can't get my code to work, I have put this in the color field of my button:  

 

If(ThisItem.'BestBeforeDate' >Today() +30, Green,Red)

 

Can anyone tell me what I am doing wrong? 

Thanks, 

1 ACCEPTED SOLUTION

Accepted Solutions
v-qiaqi-msft
Community Support
Community Support

Hi @JL6,

Then you should tell me how you define this record? For example, this record is selected in the gallery, then you could find the BestBeforeDate from this record using the following formula:

If(Gallery1.Selected.BestBeforeDate >Today() +30, Green,Red)

The key to this issue is to find the record including the BestBeforeDate you want to compare with the Today()+30

Best Regards,
Qi

View solution in original post

7 REPLIES 7
iAm_ManCat
Super User
Super User

Hi!

 

I think this is just a syntax thing, like when you do maths and leave a bracket out so its taking the comparison and then adding 30 to that. Try instead to use this 🙂

If(ThisItem.'BestBeforeDate' > (Today() +30), Green,Red)
@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


v-qiaqi-msft
Community Support
Community Support

Hi @JL6

Do you want to fill the Button with the needed color?

 

Actually, if you want to fill the Button with color, you should set the Fill property of the button:

If(ThisItem.'BestBeforeDate' >Today() +30, Green,Red)

vqiaqimsft_0-1653457910405.png

 

Best Regards,
Qi

Thanks, I tried that but Thisitem.  is not recognized when I try that. 

 

JL6_0-1653472701640.png

 

v-qiaqi-msft
Community Support
Community Support

Hi @JL6,

Could you please tell me that where do you inset this button, within a gallery?

 

Actually, only if the control exists within the Gallery or Form, you could reference to the ThisItem parameter to invoke the field value from the current record.

If you have this button outside of the Gallery of form, you should find out the date of the selected record and replace the ThisItem.BestBeforeDate

 

Best Regards,
Qi

Yes, it is outside of the gallery.  

v-qiaqi-msft
Community Support
Community Support

Hi @JL6,

Then you should tell me how you define this record? For example, this record is selected in the gallery, then you could find the BestBeforeDate from this record using the following formula:

If(Gallery1.Selected.BestBeforeDate >Today() +30, Green,Red)

The key to this issue is to find the record including the BestBeforeDate you want to compare with the Today()+30

Best Regards,
Qi
JL6
Helper I
Helper I

Thank you, that worked once I referenced the gallery! 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,139)