cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Patron
Post Patron

Collection Best Use Case

After using PowerApps for the last 6 months with varying degrees of success, the one thing I still dont exactly understand is Collections. What would be a good reason to use a collection as opposed to simply Patching the data? Is it more for storing temporary data? Can anyone here cite a good use case with Collections? Thanks. 

 

 

 

 

Brendon

1 REPLY 1
Highlighted
Community Champion
Community Champion

Re: Collection Best Use Case

Hi, 

I use collections for many things, but one usage I think that may be useful to you is using collections to store the changes you want to Patch back to the datasource.

 

Sometimes you want your changes saved immediately because the data is sensitive and you don't want things to go wrong. But saving takes time and can interrupt your user if they click too many Patches. So instead of saving one by one, you can save a bulk set of changes/additions to the data source using a collection and the ForAll() function.

 

  1. Collect the changes you want to make to chosen records
  2. Use ForAll() and conditions to either patch a new record or to update an existing record
Collect your changes somewhere:
Collect(changes,ThisItem)

Commit your changes in bulk when you are ready:
ForAll(RenameColumns(changes,"RecordId","RID"),
    If(!IsEmpty(Filter(datasource,RecordId=RID)),
        Patch(datasource,First(Filter(datasource,RecordId=RID)),
            {field: data to change
            }
        ),

        Patch(datasource,Defaults(datasource)
            {field: new data
            }
        )
    )
)

The second formula means, "For each of the records you collected for changing, check if it is already in the datasource. If it's already in there, update the data accordingly, otherwise, write a new record."

Microsoft Employee
@8bitclassroom

Helpful resources

Announcements
Check this Out

Announcing

Class of 2020- Season 2

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,995)