Citizen Developer
Timespan
explore our new search
​
Power Automate: XPath vs Apply to Each
Power Automate
Jul 29, 2026 2:40 AM

Power Automate: XPath vs Apply to Each

by HubSite 365 about Reza Dorrani

Principal Program Manager at Microsoft Power CAT Team | Power Platform Content Creator

Microsoft Power Automate expert tip use XPath to replace Apply to Each and aggregate HTTP API and SharePoint data fast

Key insights

  • XPath trick: Replace Apply to each by converting a JSON array to XML with xml() and querying it with xpath().
    This avoids looping every item when you only need targeted values or summaries.
  • Benefits: You get faster execution on large arrays, fewer actions in the flow, and a simpler design that reduces complexity and action limits.
    Use this when speed and clarity matter more than per-item processing.
  • Common operations: Use sum() for totals, first() or [0] to pick a single item, and XPath predicates to filter or group values.
    These let you compute totals, averages, and filtered results without loops.
  • Common use cases: Works well with HTTP APIs and SharePoint Get Items, plus lookups, joins, and extracting nested text from OCR or AI outputs.
    Apply it when data already arrives as arrays you need to query or aggregate.
  • How it works: Wrap the array in a root node, convert JSON to XML using xml(), run an xpath() expression to select or aggregate, then convert results back if needed.
    This single expression can replace many loop actions.
  • Caveats & best practices: Let the backend do aggregation when possible, use Select to shape data first, and prefer loops when each item needs complex logic.
    Test XPath on your data and keep expressions readable to avoid maintenance issues.

Power Automate - Power Automate: XPath vs Apply to Each

Keywords

Power Automate XPath, Replace Apply to Each Power Automate, Power Automate performance trick, Avoid Apply to Each, Optimize Power Automate flows, Use XPath in Power Automate, Improve flow performance Power Automate, XPath selector Power Automate