cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

IF record exits, increment a field, else create a new record

I'm trying to collect how many times a user has submitted a form.

 

User        Submits

David            3

 

Whenever they press the submit button again, it adds another +1 to the submit, only if the user already exists in the table, otherwise, we ll create a new record with a new user and give submits the base value of 1.

 

I have tried this formula but unfortunately, it doesn't work

 

Set(myItem,LookUp(MostActiveUsers,User=Name_Input.Text));

If(IsBlank(myItem),Patch(MostActiveUsers,{User:Name_Input.Text,Test:1)}),Patch(MostActiveUsers,myItem,{User:Name_Input.Text,Test:test+1)}))

 

Please, could anybody advise?

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps
Power Apps

Your formula seems almost correct, except for the first patch statement - it is missing the second argument. The last argument in the second Patch expression can also be updated to reference the value from myItem that you already have. Try changing it to the expression below:

Set(
    myItem,
    LookUp(MostActiveUsers, User = Name_Input.Text));
If(
    IsBlank(myItem),
    Patch(MostActiveUsers, Defaults(MostActiveUsers), {User: Name_Input.Text, Test: 1)}),
    Patch(MostActiveUsers, myItem, {User: Name_Input.Text, Test: myItem.Test + 1)}))

Hope this helps!

View solution in original post

2 REPLIES 2
Power Apps
Power Apps

Your formula seems almost correct, except for the first patch statement - it is missing the second argument. The last argument in the second Patch expression can also be updated to reference the value from myItem that you already have. Try changing it to the expression below:

Set(
    myItem,
    LookUp(MostActiveUsers, User = Name_Input.Text));
If(
    IsBlank(myItem),
    Patch(MostActiveUsers, Defaults(MostActiveUsers), {User: Name_Input.Text, Test: 1)}),
    Patch(MostActiveUsers, myItem, {User: Name_Input.Text, Test: myItem.Test + 1)}))

Hope this helps!

View solution in original post

Anonymous
Not applicable

It works! Great stuff! Thank you.

@CarlosFigueira 

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (27,926)