KEEP LEARNING
Build the bigger picture.
The Workflow Engineer connects individual n8n concepts to testing, deployment and running a complete workflow.
Tips > Building Workflows
When you need to compute summaries, totals, or grouped statistics across every item in a batch, use `$input.all()` in "Run Once for All Items" mode.
To aggregate data across every item in n8n, run a Code node in "Run Once for All Items" mode and iterate over $input.all(). Reduce the items into a single object holding totals and grouped breakdowns, and return it as one item. This is more reliable than accumulating values across a loop with the Set node.
When you need to compute summaries, totals, or grouped statistics across every item in a batch, use $input.all() in "Run Once for All Items" mode. This is far more reliable than trying to accumulate values across a loop using the Set node.
Real-world example: After fetching all invoice line items from QuickBooks, you need to produce a summary with total revenue, tax collected, and a breakdown by product category.
// Mode: Run Once for All Items
const items = $input.all().map(i => i.json);
const summary = items.reduce((acc, line) => {
acc.totalRevenue += line.amount;
acc.totalTax += line.taxAmount ?? 0;
acc.itemCount += 1;
const cat = line.category || 'Uncategorized';
if (!acc.byCategory[cat]) {
acc.byCategory[cat] = { revenue: 0, count: 0 };
}
acc.byCategory[cat].revenue += line.amount;
acc.byCategory[cat].count += 1;
return acc;
}, { totalRevenue: 0, totalTax: 0, itemCount: 0, byCategory: {} });
// Convert byCategory to an array for easier downstream use
summary.categoryBreakdown = Object.entries(summary.byCategory).map(
([name, data]) => ({ category: name, ...data })
);
delete summary.byCategory;
return [{ json: summary }];The output is a single item containing the full summary, ready to be inserted into a dashboard, sent in a report email, or stored in a database.
Related: Use Edit Fields in "Map Each" Mode for Simple Renames · Configure Payload Size and Binary Data Mode for Large Files
KEEP LEARNING
The Workflow Engineer connects individual n8n concepts to testing, deployment and running a complete workflow.
APPLY IT TO YOUR SYSTEM
Bring the process, the tools involved and an example of where the current workflow gets stuck.