The Power Automate Chunk function allows you to break down a string or array into smaller pieces of equal size.
In this article, I’ll introduce you to the chunk function and will provide a step-by-step guide on how to use the function in a Microsoft flow.
Power Automate Chunk Function
Power Automate Chunk Function
Divide a string or array into equal-sized segments.
Syntax
chunk('<collection>', '<length>')
chunk([<collection>], '<length>')
Input parameters
- collection (mandatory): The collection or string to be divided into chunks.
- length (mandatory): The size of the resulting chunks.
Return value
- Returns an array with the chunks in the defined size.
Power Automate Chunk Expression Example
// chunk expression string example
chunk('aaabbbcc', 3)
=>
[
'aaa',
'bbb',
'cc'
]
// chunk expression collection example
chunk([1,1,1,2,2,2,3], 3)
=>
[
[1,1,1],
[2,2,2],
[3]
]
// chunk expression referencing a variable
chunk(variables(‘text’), 3)
How To Use The Power Automate Chunk Function
Follow the steps to use the Power Automate Chunk function in a flow.
-
Create a new flow with trigger ‘Manually trigger a flow’
New flow
-
Add a new step by clicking on ‘+ New step’
Add a new step
-
Search for ‘initialize’ and click on ‘Initialize variable’
Add Initialize variable action
-
Setup Initialize variable: 1) Provide a name, 2) select type String, 3) Set value to ‘aaabbbcc’
Setup variable
-
Add a compose step by searching for ‘compose’ and clicking on ‘Compose’
Add Compose action
-
Setup compose action: 1) click into Inputs (popup appears), 2) click on ‘Expression’, 3) set expression to ‘chunk(variables(‘text’), 3)’ 4) click on ‘OK’
Setup chunk expression in Power Automate
-
Save and do a test run
Result test run – Power Automate chunk function example