Collection and Array Functions in Power Automate
π¦ Collection and Array Functions in Power Automate
Collection and array functions in Power Automate are essential when dealing with multiple values such as lists, tables, or JSON arrays. Whether you’re looping through a set of emails, filtering SharePoint items, or parsing data from an API, these functions help you manipulate and control grouped data with precision.
Mastering collection and array functions in Power Automate allows you to efficiently access, filter, transform, and restructure data in your flows.
π Why Use Collection and Array Functions in Power Automate?
Youβll need collection and array functions in Power Automate when:
- Looping through dynamic content (like rows or items)
- Filtering or selecting specific elements from an array
- Joining arrays or breaking them apart
- Sorting data for reporting or analysis
- Removing duplicates or transforming structures
These functions are critical when you’re using actions like “Apply to each”, “Select”, “Filter array”, or parsing JSON.
πΌ Real-World Use Cases
Use Case | Description |
---|---|
Filter SharePoint items where status = ‘Open’ | Use filter() function |
Join list of emails into one string | Use join() |
Find the highest-scoring record | Use max() on array of numbers |
Get all items assigned to a user | Use where() or filter() |
Remove duplicates from collection | Use union() or custom expression |
π§ Common Collection and Array Functions in Power Automate
Hereβs a table of frequently used collection and array functions in Power Automate:
Function | Purpose | Syntax | Example | Output |
---|---|---|---|---|
createArray() |
Creates a new array | createArray(1, 2, 3) |
[1,2,3] |
Array |
length() |
Returns number of items | length(body('Get_Items')) |
5 |
Count |
join() |
Combines array items into string | join(['A','B','C'], ',') |
A,B,C |
Text |
union() |
Merges two arrays, removes duplicates | union(array1, array2) |
Merged unique | |
intersection() |
Common items from arrays | intersection(array1, array2) |
Matching values | |
skip() |
Skips first N items | skip(array, 2) |
Remaining items | |
take() |
Takes first N items | take(array, 3) |
First 3 items | |
first() |
First item in array | first(array) |
Item1 |
|
last() |
Last item in array | last(array) |
ItemN |
|
contains() |
Checks if array has value | contains(array, value) |
true/false |
|
sort() |
Sorts array items | sort(array) |
Sorted array | |
filter() |
Filters array by condition | filter(array, condition) |
Filtered array |
π§ͺ Practical Examples of Array Functions
1. Join Email Addresses into One String
join(triggerBody()?['Emails'], ';')
Output: alice@example.com;bob@example.com;carol@example.com
2. Filter Open Tasks
filter(body('Get_Items'), item()?['Status'] == 'Open')
Use Case: Filter SharePoint list to show only open tasks.
3. Get the First Three Records
take(body('Get_Items'), 3)
Use Case: Only use the first 3 entries from a data source.
4. Merge Arrays and Remove Duplicates
union(variables('Array1'), variables('Array2'))
5. Check if Item Exists in Array
contains(variables('AssignedUsers'), 'john.doe@example.com')
β Best Practices for Collection and Array Functions
- β
Use
length()
to validate array size before looping. - β
Apply
union()
orintersection()
for deduplication or comparison. - β
Avoid unnecessary loopsβuse
filter()
andselect()
instead. - β
Use
join()
when converting arrays to strings for output or logs. - β Store results in Compose actions for easy debugging and reuse.
β οΈ Common Mistakes and How to Avoid Them
Problem | Cause | Fix |
---|---|---|
Flow fails on empty array | Accessing missing index | Use length() to check first |
Repeating items after merge | Forgetting union() |
Always use union() to deduplicate |
Array to string errors | Using + to combine values |
Use join() instead |
Unexpected results from filter() |
Bad condition syntax | Use item()?['Field'] syntax correctly |
Wrong item accessed | Index confusion | Use first() /last() or take()/skip() carefully |
π Summary: When to Use Collection and Array Functions in Power Automate
Use collection and array functions in Power Automate when you need to:
- Process grouped data dynamically
- Filter, sort, or transform items in a list
- Join array values for email or logs
- Compare data from two sources
- Access values by position (first, last, skip)