cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

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
mr-dang
Level 10

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

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

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