cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
DavidGorgan
Level: Powered On

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 Staff CarlosFigueira
Power Apps Staff

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

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 Staff CarlosFigueira
Power Apps Staff

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

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

DavidGorgan
Level: Powered On

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

It works! Great stuff! Thank you.

@CarlosFigueira 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,798)