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 / Switch Colors is not w...
Power Apps
Answered

Switch Colors is not working!

(0) ShareShare
ReportReport
Posted on by 231

I have the below buttons and I want the employee to pick where they are working from each week and when I click the button in not selected
OnFill Code

Switch(lblDay.Text,"Monday",
If(
First('Back to Work Schedule').'Monday Location' = ThisItem.Name,
varAccent,
varPrimary
), "Tuesday", If(
First('Back to Work Schedule').'Tuesday Location' = ThisItem.Name,
varAccent,
varPrimary
),
"Wednesday", If(
First('Back to Work Schedule').'Wednesday Location' = ThisItem.Name,
varAccent,
varPrimary
),
"Thursday", If(
First('Back to Work Schedule').'Thursday Location' = ThisItem.Name,
varAccent,
varPrimary
),
"Friday", If(
First('Back to Work Schedule').'Friday Location' = ThisItem.Name,
varAccent,
varPrimary
),
"Saturday", If(
First('Back to Work Schedule').'Saturday Location' = ThisItem.Name,
varAccent,
varPrimary
),
"Sunday", If(
First('Back to Work Schedule').'Sunday Location' = ThisItem.Name,
varAccent,
varPrimary
)
)

lolla70_0-1613671205788.png

OnSelect Code

Patch(
'Back to Work Schedule',
First(
Filter(
'Back to Work Schedule',
User().Email=VarUserEmail1
)
),

Switch(lblDay.Text,"Monday",
{'Monday Location': ThisItem.Name}
, "Tuesday",
{'Tuesday Location': ThisItem.Name}
, "Wednesday",
{'Wednesday Location': ThisItem.Name}
, "Thursday",
{'Thursday Location': ThisItem.Name}
, "Friday",
{'Friday Location': ThisItem.Name}
, "Saturday",
{'Saturday Location': ThisItem.Name}
, "Sunday",
{'Sunday Location': ThisItem.Name}

)

)
Any Help!

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @lolla70 

    You have a few issues in your Formulas.

    First, The OnSelect Formula has bad criteria for the First(Filter statement (by the way, don't use First(Filter - use LookUp instead)

    In that OnSelect Formula, you are comparing User().Email to VarUserEmail1.  I presume that you are setting VarUserEmail1 to User().Email somewhere in your app.  So this will always be true, which means you are really just getting the first record from your list.  I believe you want the record associated with that user instead.

    So, whatever your Email column is in the 'Back to Work Schedule' you need to substitute that into the following Formula for your OnSelect action:

    Patch(
     'Back to Work Schedule',
     LookUp('Back to Work Schedule',
     emailColumnfromList=VarUserEmail1 // substitute emailColumnfromList with the real column name from the list
     ),
     Switch(lblDay.Text,
     "Monday", {'Monday Location': ThisItem.Name}, 
     "Tuesday", {'Tuesday Location': ThisItem.Name}, 
     "Wednesday", {'Wednesday Location': ThisItem.Name}, 
     "Thursday", {'Thursday Location': ThisItem.Name}, 
     "Friday", {'Friday Location': ThisItem.Name}, 
     "Saturday", {'Saturday Location': ThisItem.Name}, 
     "Sunday", {'Sunday Location': ThisItem.Name}
     )
    )

     

    Then for your color fill property, the following formula should give you what you want:

    With({_record: LookUp('Back to Work Schedule', emailColumnfromList = VarUserEmail1)},
    
     If(
     Switch(lblDay.Text,
     "Monday", _record.'Monday Location' = ThisItem.Name, 
     "Tuesday", _record.'Tuesday Location' = ThisItem.Name,
     "Wednesday", _record.'Wednesday Location' = ThisItem.Name,
     "Thursday", _record.'Thursday Location' = ThisItem.Name, 
     "Friday", _record.'Friday Location' = ThisItem.Name, 
     "Saturday", _record.'Saturday Location' = ThisItem.Name,
     "Sunday", _record.'Sunday Location' = ThisItem.Name
     ),
     varAccent,
     varPrimary
     )
    )

     

    I hope this is helpful for you.

  • LA-27081519-0 Profile Picture
    231 on at

    Thank you so much for answering quick. I copied your code and replaced the Email by Title, but it didn't work. When I select the button it just hover and didn't get selected and copied to the SharePoint List.

    lolla70_0-1613673683182.png

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @lolla70 

    Is Title the column that would contain the User Email address (in the same letter case as User().Email)?

    Which Formula are you referring to in your last reply, the OnSelect action or the Fill property?

     

    Note: as per your original formula - if a record does NOT exist for a user, the formula will NOT create it.

    IF you need that ability, change your Formula to the following:

    Patch(
     'Back to Work Schedule',
     Coalesce(
     LookUp('Back to Work Schedule', Title=VarUserEmail1),
     Defaults('Back to Work Schedule')
     ),
     Switch(lblDay.Text,
     "Monday", {'Monday Location': ThisItem.Name}, 
     "Tuesday", {'Tuesday Location': ThisItem.Name}, 
     "Wednesday", {'Wednesday Location': ThisItem.Name}, 
     "Thursday", {'Thursday Location': ThisItem.Name}, 
     "Friday", {'Friday Location': ThisItem.Name}, 
     "Saturday", {'Saturday Location': ThisItem.Name}, 
     "Sunday", {'Sunday Location': ThisItem.Name}
     )
    )
  • LA-27081519-0 Profile Picture
    231 on at

    I want the title to be

    Title:User().FullName& " schedule created on " & Today(),

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @lolla70 

    Okay, I am confused.  You originally had User().Email = varUserEmail1 in your formula.  That will never match anything in the datasource.  So then why would you have responded that Title is what you substituted in instead, as that clearly is not what you are mentioning you want in the Title.

     

    So, I only see that you have a column in your list called Employee Name.  I would recommend that you add a Text column called EmployeeEmail, or base off of the Created By column.

    If you add a Text EmployeeEmail column, then change your formula to the following:

    Patch(
     'Back to Work Schedule',
     Coalesce(
     LookUp('Back to Work Schedule', Title=VarUserEmail1),
     Defaults('Back to Work Schedule')
     ),
     {Title: User().FullName & " schedule created on " & Today(),
     EmployeeEmail: Lower(User().Email)
     }, 
     Switch(lblDay.Text,
     "Monday", {'Monday Location': ThisItem.Name}, 
     "Tuesday", {'Tuesday Location': ThisItem.Name}, 
     "Wednesday", {'Wednesday Location': ThisItem.Name}, 
     "Thursday", {'Thursday Location': ThisItem.Name}, 
     "Friday", {'Friday Location': ThisItem.Name}, 
     "Saturday", {'Saturday Location': ThisItem.Name}, 
     "Sunday", {'Sunday Location': ThisItem.Name}
     )
    )

     

    Then change your Fill Property to:

    With({_record: LookUp('Back to Work Schedule', EmployeeEmail = Lower(User().Email))},
    
     If(
     Switch(lblDay.Text,
     "Monday", _record.'Monday Location' = ThisItem.Name, 
     "Tuesday", _record.'Tuesday Location' = ThisItem.Name,
     "Wednesday", _record.'Wednesday Location' = ThisItem.Name,
     "Thursday", _record.'Thursday Location' = ThisItem.Name, 
     "Friday", _record.'Friday Location' = ThisItem.Name, 
     "Saturday", _record.'Saturday Location' = ThisItem.Name,
     "Sunday", _record.'Sunday Location' = ThisItem.Name
     ),
     varAccent,
     varPrimary
     )
    )
  • Verified answer
    LA-27081519-0 Profile Picture
    231 on at

    It worked, but the result wasn't on the same line!!. Also still when I pick the Button for example if I click home I want the button to change the color and shows that it is picked. So in case they decided to change before click the Confirm button.

     

    lolla70_0-1613679959462.png

     

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @lolla70 

    Those are all new records...so the logic in the Patch is not correct...which I see why.

    Change the formula to this:

    Patch(
     'Back to Work Schedule',
     Coalesce(
     LookUp('Back to Work Schedule', EmployeeEmail=Lower(User().Email)),
     Defaults('Back to Work Schedule')
     ),
     {Title: User().FullName & " schedule created on " & Today(),
     EmployeeEmail: Lower(User().Email)
     }, 
     Switch(lblDay.Text,
     "Monday", {'Monday Location': ThisItem.Name}, 
     "Tuesday", {'Tuesday Location': ThisItem.Name}, 
     "Wednesday", {'Wednesday Location': ThisItem.Name}, 
     "Thursday", {'Thursday Location': ThisItem.Name}, 
     "Friday", {'Friday Location': ThisItem.Name}, 
     "Saturday", {'Saturday Location': ThisItem.Name}, 
     "Sunday", {'Sunday Location': ThisItem.Name}
     )
    )

    I forgot to update the LookUp criteria.

  • LA-27081519-0 Profile Picture
    231 on at

    Thank you so much, It finally worked correctly. Quick question, do you have YouTube channel? or do you recommend a book to start with for PowerApps!

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @lolla70 

    Yes...at the bottom of this post you will see my signature line.  It has a link to my YouTube channel.

     

  • LA-27081519-0 Profile Picture
    231 on at

    One more thing please, how to reset the button after send confirmation. 

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 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard