Splitting, Aggregating, and Summarizing Data
1. Splitting, Aggregating, and Summarizing Data
In real-world data, information is rarely flat.2. Splitting Out: Dealing with Nested Data
Invoices contain charges, orders contain line items, and customers have multiple addresses. When we receive an invoice with five separate charges, n8n sees that as one item — one invoice object with a nested array inside it. But what if we need to process each charge individually?3. Example: Processing Invoice Payments
Here's a Manual Trigger with four invoices pinned — each has a client name, an invoice ID, and a charges array listing the department, hours, and rate. Right now, n8n sees four items. But we need to work with each charge individually. Add a Split Out node and set the field to "charges." By default, Split Out only keeps the nested fields — but we need the parent fields too, like invoice_id and client. Change the Include option to "All Other Fields." Now execute, and look at the output — four invoices just became twenty individual charge items, each carrying its invoice ID and client along with it. That handles breaking data apart. But once we've processed each item, we often need to put things back together — grouped by invoice, by customer, or by whatever makes sense.4. Split, Process, and Reassemble
That's the split, process, reassemble pattern — and it's one of the most common data flows in n8n. Split Out breaks a nested array into individual items, you process each one, and then the Aggregate node collects them back into a single item. Think of it as the reverse of Split Out — many items go in, one item comes out with everything nested in a data array.5. Example: Split, Process, and Reassemble
Back in our workflow, after Split Out, add an Edit Fields node — call it Calculate Charge Total — and create one field: charge_total, set to the expression hours times rate. Each charge now has its own calculated total. Next, add an Aggregate node — set it to "All Item Data" and leave the defaults. Execute the whole workflow — four invoices split into twenty charges, each gets a calculated total, and Aggregate collects them all back into a single item with a data array containing every processed charge. That's the split, process, reassemble pattern in action — and it handles most complex data scenarios you'll run into.6. Summarizing Data
Sometimes you don't need to reassemble — you just need stats. That's where the Summarize node comes in. Remove the Edit Fields and Aggregate nodes, and add a Summarize node after Split Out instead. Set it to sum the "hours" field, grouped by "department." Executing this, we see twenty charges go in, and four department totals come out. It's like a pivot table in a spreadsheet: define what to group by and what to calculate, and Summarize does the rest. So Aggregate collects items back into a single nested structure. Summarize computes statistics across items. Different tools for different jobs. Here's the vocabulary to keep in mind.7. Summary
Split Out means "one becomes many" — it explodes a nested array into individual items. Aggregate means "many become one" — it collects processed items back into a single nested structure. And Summarize means "many become stats" — it computes values like sums and counts across items.8. Let's practice!
In the exercises, you'll work with order data containing line items — a different dataset from our invoices, but the exact same patterns apply. Time to practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.