Skip to content

Solving Array SUM() with Custom Connectors

Power Automate Math Sucks

If you’ve ever tried to do something simple like sum a bunch of values in an array in Power Automate Cloud Flows, you’ve probably learned two things:

  1. You’ll need to loop (Apply to each) — which is slow, ugly, and breaks concurrency.
  2. There’s no built-in way to just sum, map, or filter like you can in every other language on Earth.

So instead of putting up with this (and because I really didn’t want to loop through 10k items every time), I built a custom connector called sumBySchema that gives you proper math operations in a single action. No Apply to each, no jank.

The Problem

Say you have data like this:

jsonCopyEdit[
{ "count": 5, "size": 2000 },
{ "count": 10, "size": 3000 }
]

All you want is to total the count and size. That’s one line in most languages. In Power Automate? You’re looping through the array manually, maybe using variables, or composing it into another array first. It’s tedious and painfully slow.

Even worse: if your structure looks like this…

jsonCopyEdit{
"email": [ { "count": 5 }, { "count": 7 } ],
"onedrive": [ { "count": 2 }, { "count": 3 } ]
}

…then Power Automate basically taps out unless you go full JSON builder mode.


What We Wanted

We wanted something that could take any of these patterns:

  • A flat array of numbers: [10, 20, 30]
  • A flat array of objects: [{"count": 5}, {"count": 10}]
  • A nested structure: {"email": [..], "calendar": [..]}

And spit out something like:

jsonCopyEdit{
"email.count.sum": 12,
"count.sum": 12
}

All in a single step, using a schema we define, not a hardcoded loop.


The Solution: sumBySchema

We made a single custom connector action that accepts:

  • A schema — basically a map of what you want to extract and sum
  • Either an array or an object of arrays
  • It returns only the things you asked for in your schema — not everything it finds

Example 1: Flat array of objects

jsonCopyEdit{
"array": [
{ "count": 5, "size": 2000 },
{ "count": 10, "size": 3000 }
],
"schema": {
"": ["count", "size"]
}
}

Returns:

jsonCopyEdit{
"count.sum": 15,
"size.sum": 5000
}

Example 2: Object of arrays

jsonCopyEdit{
"object": {
"email": [ { "count": 5 }, { "count": 7 } ],
"calendar": [ { "count": 2 }, { "count": 3 } ]
},
"schema": {
"email": ["count"],
"calendar": ["count"]
}
}

Returns:

jsonCopyEdit{
"email.count.sum": 12,
"calendar.count.sum": 5,
"count.sum": 17
}

It’s fast, flexible, and does all the heavy lifting in a single call.


Why a Custom Connector?

We originally explored Select, Filter, Reduce logic with expressions, but it quickly got messy. Power Automate doesn’t support functional array operations natively. And even if you do manage it, it’s unreadable.

By offloading the logic to a custom connector, we:

  • Cut down flow steps by 80%
  • Got rid of loops
  • Made it dead simple to read and reuse

Plus, because it’s written in C# using the x-ms-code feature, it runs server-side without hitting a real endpoint — it’s just logic, inline.


Bonus: It Only Returns What You Asked For

No junk in the output. If it’s not in the schema, it’s not in the output. You control what gets summed, and nothing else leaks through. Clean in, clean out.

WANT THE CUSTOM CONNECTOR?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.