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
PowerApps Staff CarlosFigueira
PowerApps 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
PowerApps Staff CarlosFigueira
PowerApps 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
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Demo Extravaganza Championship Voting Open

Voting Ends: October 30, 2019!

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 335 members 5,114 guests
Please welcome our newest community members: