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
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (1,350)