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.

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)

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

191 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book a 20-minute call