cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Community Champion
Community Champion

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

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (38,102)