Power Automate Chunk Function Explained

Power Automate Chunk Function

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 expression
chunk expression in Power Automate

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.

  1. Create a new flow with trigger ‘Manually trigger a flow’

    Power Automate Chunk Function new flow

    New flow

  2. Add a new step by clicking on ‘+ New step’

    Power Automate Chunk Function new step

    Add a new step

  3. Search for ‘initialize’ and click on ‘Initialize variable’

    Power Automate Chunk Function initlalize variable

    Add Initialize variable action

  4. Setup Initialize variable: 1) Provide a name, 2) select type String, 3) Set value to ‘aaabbbcc’

    Power Automate Chunk Function setup initialize variable

    Setup variable

  5. Add a compose step by searching for ‘compose’ and clicking on ‘Compose’

    Power Automate Chunk Function add compose

    Add Compose action

  6. 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’

    Power Automate Chunk

    Setup chunk expression in Power Automate

  7. Save and do a test run

    power automate chunk function test run result

    Result test run – Power Automate chunk function example

Leave a Comment

Your email address will not be published. Required fields are marked *