π Power Automate Tip: Accessing Specific Items in JSON Without “Apply to Each
One of the most common frustrations in Power Automate is dealing with the “Apply to each” loop when you only want a single item from an array (for example, the 4th item).
Loops add unnecessary complexity, slow down your flow, and make debugging harder. Luckily, you can avoid them with simple array indexing expressions.
✅ The Scenario
Let’s say you’re using the SharePoint “Get items” action to pull Paid Time Off (PTO) requests.
The output looks like this:
You only need the 4th item (Maternity Leave) — but without looping through everything.
π Two Easy Solutions
1️⃣ Direct Index Reference
Power Automate arrays are zero-based, so the 4th item is at index [3]
.
Expression:
π Output: Maternity Leave
2️⃣ Using skip()
Function
Another neat trick is using skip()
to drop the first N items and grab the next one.
Expression:
π This skips the first three items and returns the 4th.
⚠️ Best Practice: Handle Missing Data
What if the list doesn’t have four items? To avoid errors, wrap your expression with a condition:
π If there are fewer than 4 items, the flow safely returns “Not Found” instead of failing.
π― Bonus: Get the Last Item
Want the last record, regardless of length? Use:
Perfect for “latest record” scenarios!
✨ Final Thoughts
By using array indexing and functions like skip()
and last()
, you can eliminate unnecessary Apply to each loops in Power Automate.
This makes your flows:
-
π Faster
-
π§Ή Cleaner
-
π Easier to maintain
Next time you need a single item from a JSON array, skip the loop and go direct. π
Comments
Post a Comment