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
CarlosFigueira
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
CarlosFigueira
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!

Anonymous
Not applicable

It works! Great stuff! Thank you.

@CarlosFigueira 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (3,688)