cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Power Apps
Power Apps

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
Highlighted
Power Apps
Power Apps

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

Highlighted
Frequent Visitor

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

It works! Great stuff! Thank you.

@CarlosFigueira 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,183)