Shorten loops with take() while testing
Quiz question
What does take(array, 5) return if the array has only three items?
Solution
- A) All three items, without an errorCorrect. take() returns at most the given number. If there are fewer, all existing items come back.
- B) An error, because items are missingWrong. take() does not fail when the array is shorter than the requested number.
- C) Three items plus two empty onesWrong. take() does not fill anything up. It only cuts off what goes beyond the number.
What it is about
Testing a loop over hundreds of items costs time and actions on every run. With take() you process only the first items while testing. You replace the input of Apply to each with an expression like take(body('Select'), 5). The loop then runs at most five times, no matter how large the array is. If the array has fewer items, take() simply returns all of them, without an error. This way you check the logic inside the loop on a few real records. Once everything works, you remove take() and select the original output again. The structure of the flow stays unchanged.
When to use it, when not
Use it
When testing loops over large lists or tables, before you let the flow loose on all data.
Better not
In production. If take() stays in the flow, it permanently processes only the first items.
Most common mistake
Forgetting take() in the flow after testing. A note on the action reminds you to remove it again.
License
Standard This technique uses standard connectors. Microsoft 365 usage rights cover standard connectors. Check the rights for your whole flow. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.
Share
Short link: powerautomate.ninja/en/148
Source: PowerPlatformTip #148, Microsoft Learn: Reference for functions in workflow expressions.
Prefer to continue with guidance? The Power Automate live course (in German) at the Power Platform Academy runs over four weeks. The next dates are not set yet, you can join the waiting list on the course page.