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 / Default Value on Toggle
Power Apps
Answered

Default Value on Toggle

(0) ShareShare
ReportReport
Posted on by 4

Hi, 

I'm farely new to powerapps but am involved in building an app for my University professor to enable him to schedule the work of his apprentices more easily.

Skärmavbild 2019-06-05 kl. 12.07.31.png


The apprentices receives this gallery of scheduled work shifts. If the apprentice is available for work they just chech the toogle for that specific shift and the information is saved in an Azure database.

The problem is that when the powerapp is turned off, the toggle value is immediately turned to false. To solve this, I created a column in the database called ToggleValue, and whenever the Toggle is checked I use Patch to change the ToggleValue for that specific record to "True" and "False" when unchecked:

Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]';ID = ThisItem.ID);{ToggleValue: "True"}) 
Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID);{ToggleValue: "False"})

 

I then set the Default value of the toggle to:

If(ThisItem.ToggleValue = "True"; true; ThisItem.ToggleValue = "False"; false)

This works fine when I check the toggles, except when I check the one connected to the first record in the gallery. When doing that it seems like a chain event is created that checks every single toggle.

Any ideas on why this is occurring? Any suggestions on altering the code to make this work?

Thanks,
Philip. 

Categories:
I have the same question (0)
  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @PhilipS ,

    Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned.

     

    Please consider remove the formulas from the OnCheck property and OnUncheck property of the Toggle control, instead, set the OnSelect property to following:

    If(
     Toggle1.Value = true;
     Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID); {ToggleValue: "True"});
    Patch('[dbo].[Timeedit_data]'; LookUp('[dbo].[Timeedit_data]'; ID = ThisItem.ID); {ToggleValue: "False"}) )

    set the Default property of the Toggle control to following:

    If(ThisItem.ToggleValue = "True"; true; false)

     

    If the issue still exists, please consider use the UpdateIf function to update the ToggleValue instead of using Patch function. Set the OnSelect property of the Toggle control to following:

    If(
     Toggle1.Value = true;
     UpdateIf('[dbo].[Timeedit_data]'; ID = ThisItem.ID; {ToggleValue: "True"});
      UpdateIf('[dbo].[Timeedit_data]'; ID = ThisItem.ID; {ToggleValue: "False"})
    )

    Please take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • PhilipS Profile Picture
    4 on at

    Worked like a charm, thank you sir!

  • peterstylias Profile Picture
    38 on at

    @v-xida-msft , what would be my default value if i just want to retain the value of the toggle when i press edit.  i have a toggle that says yes and no.  when i select yes and hit submit, it will be saved on the excel data as yes.  when i come back to the same record and hit edit, it would automatically come back to no.  it will not remember the previous data.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 377 Most Valuable Professional

#2
11manish Profile Picture

11manish 165 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 110 Super User 2026 Season 2

Last 30 days Overall leaderboard