How to Use the Chunk() Function in Power Automate

Introduction

In this blog, we’ll explore the Chunk() function in Power Automate, which splits a large array or string into smaller, equal-sized parts. This function is extremely useful when working with big datasets.

Purpose of the Chunk() Function

The main purpose of the Chunk() function is to break a big list or long string into smaller parts so it becomes easier to work with in Power Automate. Instead of processing everything at once, you can process data in small batches, which helps avoid errors and improves throughput. It is helpful when you have too many items to handle at once, or when you want to handle items in small parts so your flow does not get overloaded.

Syntax of the Chunk() Function

For Array

chunk(<array>,<length>)

For String

chunk('<String>',<length>)

Example: Chunk a String

chunk('Power Automate',3)

In Input, I used the string "Power Automate" and split it into parts of 3 characters each. The space before "Automate" is also counted as a character, so it is included in the chunks just like the letters.

Output

[
  "Pow",
  "er  ",
  "Aut",
  "oma",
  "te"
]

Example: Chunk an Array

chunk(createArray(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),4)

I passed the input array of numbers from 1 to 16 using createArray function, and it is divided into small parts of 4 items each.

Output

[
    [
        1,
        2,
        3,
        4
    ],
    [
        5,
        6,
        7,
        8
    ],
    [
        9,
        10,
        11,
        12
    ],
    [
        13,
        14,
        15,
        16
    ]
]

Conclusion

In short, the Chunk() function is very useful to break arrays or strings into smaller parts so you can handle data easily and step by step.