Tips > Building Workflows

Aggregate Data Across All Items With `$input.all()`

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.

TipIntermediate2 min read

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 }];
```text
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](../data-transformation/01-use-edit-fields-in-map-each-mode-for-simple-renames.md) | [Configure Payload Size and Binary Data Mode for Large Files](../performance-and-large-files/01-configure-payload-size-and-binary-data-mode-for-large-files.md)

Want this running in your stack?

I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.