Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 6nx+vAWJl5+DyUvJVEukvA
Power Apps - Building Power Apps
Answered

How to increment/decrement a text input field based on toggle selection

Like (0) ShareShare
ReportReport
Posted on 14 Jan 2021 21:44:03 by

I building a custom form off a SharePoint list that has about 20 yes/no fields and a text field named Total Points. What I want to do is on the PowerApps form, use toggles for the Yes/No fields and set them up so that if the toggle is selected/yes, one point is added to Total Points. If a toggle is unselected/no, then one point is subtracted from the total. 

 

I've tried to do this using a global variable and incrementing/decrementing it using the On Check and On Uncheck function on the toggle fields. So when the app opens the variable is set to 0, then if Toggle A is selected the On Check function uses the following to increment the variable:

 

Set(varPoints, varPoints+1)

 

If the user turns off the toggle, the On Uncheck formula is Set(varPoints, varPoints-1)

 

The Total Points field is getting updated as I expected. But when I edit an item when the form opens it's incrementing the Total Points without any action on my part, adding to it. It's as if the app is checking and sees that some toggles are selected and adding 1 for each one selected. 

 

I'm trying to have the form open with the Total Points showing based on the number of toggles selected and not change unless a change is made to a toggle.

  • Community Power Platform Member Profile Picture
    on 15 Jan 2021 at 20:48:47
    Re: How to increment/decrement a text input field based on toggle selection

    Thanks. Two questions:

     

    The "DataCardValueN.Value" above refers to the name of the slider data cards?

     

    In "Refresh(increments)" what does "increments" indicate, the slider data cards again?

  • Verified answer
    CU24091509-0 Profile Picture
    417 on 15 Jan 2021 at 20:10:10
    Re: How to increment/decrement a text input field based on toggle selection

    Looks like there is a timing thing going on. 

     

    This is what i have done.

    Insert a timer and set the value to may be 3000 milli seconds

    on timer end Set(vartotals,Value(SharePointIntegration.Selected.Title))

     

    Default for Totals Data card vartotals

     

    SharePoint integration on save

    Set(
    vartotals,
    0
    );
    If(
    DataCardValue2.Value,
    Set(
    vartotals,
    vartotals + 1
    )
    );
    If(
    DataCardValue3.Value,
    Set(
    vartotals,
    vartotals + 1
    )
    );
    If(
    DataCardValue4.Value,
    Set(
    vartotals,
    vartotals + 1
    )
    );
    SubmitForm(SharePointForm1);

     

    OnEdit, OnView,OnNew :Refresh(increments);

    Hope this helps.

     

     

    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

  • Community Power Platform Member Profile Picture
    on 15 Jan 2021 at 19:25:33
    Re: How to increment/decrement a text input field based on toggle selection

    I thought I would provide more details. Here is how I have this app set up now, trying to follow you directions. The biggest problem at the moment is that when I create a new item, switching the toggle is not incrementing the Total Points field.

     

    App

    OnStart: Set(varID,SharePointIntegration.SelectedListItemID); Set(varPoints,0); Set(varSelected,SharePointIntegration.Selected.'Total Points');

     

    SharePointIntegration

    OnNew: NewForm(SharePointForm1);

     

    OnSave: SubmitForm(SharePointForm1)

     

    FormScreen1

    OnVisible: Set(varPoints, Value(varSelected))

     

    Total_Points_DataCard1

    text input: DataCardValue15>Default: Parent.Default

     

    Toggle control

    OnChange: If(Self.Value,Set(varPoints,varPoints+1),Set(varPoints,varPoints-1))

     

  • Community Power Platform Member Profile Picture
    on 15 Jan 2021 at 17:07:12
    Re: How to increment/decrement a text input field based on toggle selection

    So this is a SharePoint list customized form, and when they select New in SHarePoint I want to load the form, and not a gallery. Could you show how these variables and settings would work with a custom form that has the OnNew, OnSave, etc. settings? I appreciate your help. I'm just struggling to translate your solution to my custom form.

  • CU24091509-0 Profile Picture
    417 on 15 Jan 2021 at 16:45:19
    Re: How to increment/decrement a text input field based on toggle selection

    Please use this. This should work for you.

     

    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

  • CU24091509-0 Profile Picture
    417 on 15 Jan 2021 at 15:24:32
    Re: How to increment/decrement a text input field based on toggle selection

    Let me take a look at it and give you a solution.

  • Community Power Platform Member Profile Picture
    on 15 Jan 2021 at 14:41:07
    Re: How to increment/decrement a text input field based on toggle selection

    A little more analysis seems to reveal the following: the OnNew property for the app sets the varPoints variable to 0. But when I open a new item, it seems to be looking at the last item I added, turning off the toggles that were selected, and since those are essentially being unchecked, it's decrementing the start value. So, I create a new item, select 7 toggles so that the Totals is 7. Then if I open a new item in the list, the form appears with all the toggles deselected, but the Totals field is showing -7.

     

    Still not able to edit an item and have the Totals field increment or decrement when toggles are checked or unchecked.

  • Community Power Platform Member Profile Picture
    on 15 Jan 2021 at 13:24:28
    Re: How to increment/decrement a text input field based on toggle selection

    Thanks, Kranthi. You solution fixed the problem of the Total field automatically updating. The problem I'm having now is that when I edit an item that was added to the SharePoint list, if I select additional toggles, they are not incrementing the Total field. Also, when I add a new item, the Total field is not defaulting to 0.

     

    For example: I add my first item to the list. Total field = 0. I select 4 toggles and Total field goes to 4. Save item. Then edit item and select additional toggles. Total remains at 4.

     

    After adding the first item I add a new item to the list. On this item the Total field is defaulting to -4, not 0. Maybe there are issues with how the form is updating the list, resets that I need to consider, etc.?

  • CU24091509-0 Profile Picture
    417 on 14 Jan 2021 at 22:29:02
    Re: How to increment/decrement a text input field based on toggle selection

    Hi @Anonymous  I tried to replicate your issue and it works perfectly fine for me.

    If(Form1.Mode=FormMode.New,vartotal, Parent.Default) i used this on my totals text field.

     

    I am also attaching my sample app here.

    Using SP and all the fields are defaulted to No.

     

    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

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard