cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dtsiniavskyi
Kudo Collector
Kudo Collector

Collect or update

Is there some function that implements CollectOrUpdate logic? For example if table contains a record, filtered by some logical expression, then we will Update() this record, othervise - Collect() new one. Now I have to use the next formula to do this:

 

 

If(CountRows(Filter(Pages, Category = TextInput1.Text)) = 0, Collect(Pages, { Category: TextInput1.Text, Page: Value(TextInput2.Text)}), Update(Pages, LookUp(Pages, Category = TextInput1.Text), { Category: TextInput1.Text, Page: Value(TextInput2.Text) }))

 

If() Count() of matched rows in my Pages collection is 0 then we Collect() new entry. Othervise we Update() or Patch() the entry that LooksUp() by the expression.

 

But it is kinda bulky, is there more elegant solution?

1 REPLY 1
mr-dang
Community Champion
Community Champion

I don't have a more efficient formula, but you might like the Ctrl+Enter shortcut. It puts a carriage return in the formula bar so that you can add more organization to your formula:

 

If(CountRows(Filter(Pages, Category = TextInput1.Text)) = 0, 
Collect(Pages, { Category: TextInput1.Text, Page: Value(TextInput2.Text)}), 
Update(Pages, LookUp(Pages, Category = TextInput1.Text), { Category: TextInput1.Text, Page: Value(TextInput2.Text) }))
Microsoft Employee
@8bitclassroom

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,479)