What's new in Power Platform? - Ep 11

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

No alt text provided for this image
List rows to create my array (I've simplified this)

Next I will select the relevant column to get a simple array:

No alt text provided for this image

We then use the length function to get the length of our array

No alt text provided for this image
Expression: length(body('Select_GetTheAccountGUID'))

We then divide the length of the array by 10 - as we are using 10 application users

No alt text provided for this image
div(outputs('Compose_GetLengthOfArray'),10)


We now have our array, and the length of our chunks, so can use the chunk function.

No alt text provided for this image
chunk(body('Select_GetTheAccountGUID'),outputs('Compose_DivideLengthOfArrayBy10'))


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!

No alt text provided for this image
Expression used in Select an output from previous steps: outputs('Compose_ChunkArray')[0]

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"

No alt text provided for this image

and press ctrl + v on your keyboard, you will then see the action available for use:

No alt text provided for this image

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

#powerplatform?#powerapps?#poweraddicts?#lowcodenocode?#WNIPP

要查看或添加评论,请登录

Stuart Baxter的更多文章

  • The death of Ribbon Workbench?

    The death of Ribbon Workbench?

    Firstly, I'd like to give Scott Durow?? a huge shout out! Ribbon Workbench has been an essential tool for Model Driven…

    44 条评论
  • The recipe for a successful software project

    The recipe for a successful software project

    I recently had a conversation with Charlie W. White about different types of developers, and I wanted to expand on it a…

    1 条评论
  • What's new in Power Platform? - Ep 18

    What's new in Power Platform? - Ep 18

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    7 条评论
  • What's new in Power Platform? - Ep 17

    What's new in Power Platform? - Ep 17

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    7 条评论
  • What's new in Power Platform? - Ep 16

    What's new in Power Platform? - Ep 16

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    1 条评论
  • What's new in Power Platform? - Ep 15

    What's new in Power Platform? - Ep 15

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    1 条评论
  • What's new in Power Platform? - Ep 14

    What's new in Power Platform? - Ep 14

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    6 条评论
  • What's new in Power Platform? - Ep 13

    What's new in Power Platform? - Ep 13

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

  • What's new in Power Platform? - Ep 12

    What's new in Power Platform? - Ep 12

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    8 条评论
  • February Update

    February Update

    You may have noticed that I haven't written an article for a few weeks, so I wanted to give you an update on the things…

    5 条评论

社区洞察

其他会员也浏览了