Saltar al contenido

Lección 8 · Data and Expressions

Transforming Data Without Code

Reshape data in n8n with Edit Fields, Sort, Limit, Split Out, Aggregate, Summarize and Remove Duplicates, and learn how to choose the right node for each job.

Raw data rarely arrives in the shape your next step needs. Before you reach for code, check whether a built-in node can do the job. Built-in nodes are easier to read, and a colleague can understand them at a glance.

The toolbox

Node Use it to
Edit Fields (Set) Add, rename or build fields
Filter Keep only items that pass a condition
Sort Order items
Limit Keep a number of items
Split Out Turn a list field into separate items
Aggregate Combine items into a list or one item
Summarize Totals, counts and groups, like a pivot table
Remove Duplicates Drop repeats

Filter appears again with the branching nodes in If, Switch and Filter.

Edit Fields

Use Edit Fields to prepare clean records. Typical work: rename Email Address to email, join first and last name, or add a timestamp. You can choose whether to keep the other input fields or only the ones you define. Keeping only what you need is a good habit, especially before sending data to an outside service.

TEXT
fullName    = {{ $json.first }} {{ $json.last }}
email       = {{ $json['Email Address'].trim().toLowerCase() }}
importedAt  = {{ $now.toISO() }}

Split, sort, limit

Imagine an API returns { "results": [ ... ] }. A typical chain is:

flowchart LR
  A["Split Out: results"] --> B["Filter: active"]
  B --> C["Sort: newest first"]
  C --> D["Limit: 5"]

Turn one reply into items, keep the useful ones, and pick the top few.

Order matters. If you limit before filtering, you may throw away the items you wanted.

Summarize and aggregate

Aggregate collects values into lists, which is ideal before one message that describes everything. Summarize computes numbers, such as the sum of order totals per country.

Python Stand-in: filter, group and total

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Remove Duplicates

Duplicates happen when sources overlap or a trigger delivers the same event twice. The node has two main uses:

  1. Within the current input: remove repeated records in this run, comparing all fields or chosen ones.
  2. Across executions: remember values processed in earlier runs, so you handle only new ones. This history has a limit, and you can clear it.

Choose a stable key such as an order ID. A name or timestamp is a poor key, because two real records can share it.

JS Stand-in: remember what you already processed

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Storing small data

n8n also has data tables, a built-in place to keep simple rows between runs, such as lists of processed IDs or settings. There are storage limits that differ by version and plan, so check the current documentation. For large or important data, use a real database. You can learn to query one in the SQL tutorial.

Which node should you use?

  • Changing the fields of each item: Edit Fields.
  • Dropping items: Filter.
  • One list to many items: Split Out.
  • Many items to one: Aggregate or Summarize.
  • Something none of these handles cleanly: the Code node.

Common mistakes

  • Limiting or sorting before filtering.
  • Using a changing value, such as "received at", as the duplicate key.
  • Passing every field onward, including personal data the next service does not need.

Plan the output first

Write the record you want at the end, for example {country, orders, revenue}, and work backwards. Which fields must exist before grouping? Which rows must be removed first? Which values need conversion from text to numbers? Once you know the target shape, the order of nodes usually becomes clear: split, clean, filter, group, sort and limit. After each node, check the item count. If the count drops unexpectedly, the filter condition or a duplicate key is the first suspect. Record counts such as "250 read, 12 removed as test data" in a summary message, so a silent change in the source gets noticed.

Practice

Given sales rows with region, product, amount and date, plan a node chain that shows the top three regions by revenue for last month. Write the order of the nodes and explain why filtering by date comes before summarizing. Decide how you handle rows with a missing region or an amount stored as text. Then check your plan against a small hand-made table, calculating the expected totals yourself. If the workflow result and your hand total differ, inspect item counts after each node until you find the step where they diverge.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Which node works most like a pivot table?

    Summarize computes totals and counts across groups.
  2. 2. What is a good key for removing duplicates?

    A stable unique identifier distinguishes records reliably.
  3. 3. Why keep only needed fields before calling an outside service?

    Sharing less data reduces privacy risk.

Summary

  • Built-in nodes cover most reshaping tasks.
  • Split Out and Aggregate move between lists and items.
  • Remove Duplicates works within a run or across runs; choose a stable key.
  • Filter early, then sort and limit, and keep only the data you need.

Next: The Code Node: JavaScript and Python

Tu progreso se guarda en este navegador. No necesitas una cuenta.