What's new in Power Platform? - Ep 11
Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect at?Kerv Digital. I've been working with Microsoft technologies for almost 8 years and have spent the last 4 working with Power Platform. I enjoy building creative solutions for our customers using the latest features.
In this episode, we will be looking at the new "Chunk" function for Power Automate.
Although this feature is a few months old, I've found a really great use cases for it recently and wanted to share this.
What does the Chunk function do?
Chunk takes a large array or sting, and splits it into smaller arrays or strings of equal length.
Working with Strings
chunk(*string*, '<length>')
Working with Arrays
chunk([<collection>], '<length>'))
Example use case
I recently had a requirement to make an update to calculate the date that a record should be deleted, based on associated records. I was able to calculate the deletion date based on some fairly simple logic, but was hitting service protection limits, and found the flow to be super slow (we were dealing with 100k records per flow run). I tried using an application user, but it still took a long time to run. A colleague of mine have previously developed a console app that addressed this exact issue by splitting the updating of records across 10 application users, which inspired me to come up with this approach.
Chunk to the rescue!
We start with a list rows to get our array (I have set pagination to 100k in settings):
Next I will select the relevant column to get a simple array:
We then use the length function to get the length of our array
We then divide the length of the array by 10 - as we are using 10 application users
We now have our array, and the length of our chunks, so can use the chunk function.
领英推荐
If our list rows was gave us 100 records, we would end up with 10 arrays of 10 accounts.
We can then pass one chunk into an apply to each, and take action on that record!
using parallel branches we can repeat the above using something like:
outputs('Compose_ChunkArray')[X]
where X = a number between 0 and 9.
In place of our compose action, we can add whatever action you wanted to take on your records.
Try it yourself
If you want to use this approach, you can simply copy the below code
{"id":"a234b40a-5c36-4d33-9dc1-3bb037554f49","brandColor":"#8C3900","connectionReferences":{"shared_commondataserviceforapps":{"connection":{"id":"/cr446_sharedcommondataserviceforapps_f8e24"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Scope","operationDefinition":{"type":"Scope","actions":{"List_Rows_Get100KAccounts":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_commondataserviceforapps","operationId":"ListRecords","apiId":"/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"},"parameters":{"entityName":"accounts"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"runtimeConfiguration":{"paginationPolicy":{"minimumItemCount":100000}}},"Select_GetTheAccountGUID":{"type":"Select","inputs":{"from":"@outputs('List_Rows_Get100KAccounts')?['body/value']","select":{"Account":"@item()?['accountid']"}},"runAfter":{"List_Rows_Get100KAccounts":["Succeeded"]}},"Compose_GetLengthOfArray":{"type":"Compose","inputs":"@length(body('Select_GetTheAccountGUID'))","runAfter":{"Select_GetTheAccountGUID":["Succeeded"]}},"Compose_DivideLengthOfArrayBy10":{"type":"Compose","inputs":"@div(outputs('Compose_GetLengthOfArray'),10)","runAfter":{"Compose_GetLengthOfArray":["Succeeded"]}},"Compose_ChunkArray":{"type":"Compose","inputs":"@chunk(body('Select_GetTheAccountGUID'),outputs('Compose_DivideLengthOfArrayBy10'))","runAfter":{"Compose_DivideLengthOfArrayBy10":["Succeeded"]}},"ApplyToEach_Batch0":{"type":"Foreach","foreach":"@outputs('Compose_ChunkArray')[0]","actions":{"Compose_DisplayAccountGUID0":{"type":"Compose","inputs":"@item()?['Account']","runAfter":{}}},"runAfter":{"Compose_ChunkArray":["Succeeded"]}},"ApplyToEach_Batch1":{"type":"Foreach","foreach":"@outputs('Compose_ChunkArray')[1]","actions":{"Compose_DisplayAccountGUID1":{"type":"Compose","inputs":"@item()?['Account']","runAfter":{}}},"runAfter":{"Compose_ChunkArray":["Succeeded"]}}},"runAfter":{}}}
then add an action, select "My Clipboard"
and press ctrl + v on your keyboard, you will then see the action available for use:
Conclusion
The chunk function is a really useful function, and allows users to split larger arrays into smaller arrays for a variety of use cases, in particularly useful one is splitting arrays into smaller chunks to pass to application users.
I hope you enjoyed this episode of What's new in Power Platform - please join us again next week where I'll be diving into another great new feature!
To keep up to date with the latest posts, please follow me or?What's new in Power Platform blog