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.

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.

What does $input.all() do in n8n?

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.

How do you aggregate data across all items with $input.all()?

// 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.

When should you use "Run Once for All Items" mode?

  • You need summaries, totals, or grouped statistics computed across every item in a batch.
  • You would otherwise accumulate values across a loop with the Set node, which is far less reliable.

Related: Use Edit Fields in "Map Each" Mode for Simple Renames · Configure Payload Size and Binary Data Mode for Large Files

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

190 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 an introductory call