Tool-page

Apply to Each to First

Turn an Apply to each loop into single actions and replace item() and items('loop') with first(collection).

When a collection holds exactly one item, the loop is unnecessary. The tool takes the loop node from the clipboard or from code view ("type": "Foreach"), pulls the actions out and inserts first(...). Inside inner loops item() stays unchanged, because there it refers to the inner loop's item.

Open Apply to Each to First

Free. You enter your email address once, then all tools are unlocked. Your data is processed locally in your browser.

How it works

  1. Copy the loop node in the designer or take it from code view.
  2. Paste the JSON here and convert it.
  3. Paste the result into your flow and check runAfter.

Example: item() to first()

// before (inside Apply to each over outputs('Get_items')?['body/value'])
@items('Apply_to_each')?['Title']
@{item()?['Title']}

// after (no loop)
@first(outputs('Get_items')?['body/value'])?['Title']
@{first(outputs('Get_items')?['body/value'])?['Title']}

Frequently asked questions

Is the tool free?

Yes.

Is my flow data uploaded?

No, the conversion runs locally in your browser.

When does this make sense?

When a collection is sure to hold exactly one item, for example Get items filtered on an ID. Then you access it directly with first(...) (tip 123).

Which formats does the tool accept?

The clipboard of the new and the classic designer and JSON from code view, including the form {"Apply_to_each": {...}}.

What about nested loops?

Inside inner loops item() stays unchanged. Only items('outer loop') and the inner loop's collection are replaced. The tool shows a note when it finds inner loops.

What if the collection is empty?

first() then returns null. With ?[...] as in first(...)?['Title'] the flow keeps running.

Related tips

All tips in the archive

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.