DEV Community

Robert Breen
Robert Breen

Posted on Originally published at learn.ynteractive.com

n8n Filter Node: Six Leases In, Three Out. Open the Discarded Pile Before You Trust It (Then Clean Up With Edit Fields)

Most office lists are mostly noise. Forty rows, and six need something done today.

In n8n the step that finds those six is the Filter node, and the step that turns each one into something readable is Edit Fields (Set). Together they shorten a list with no code. This walkthrough uses a made-up property management office that needs to send renewal offers before leases run out.

Manual trigger  →  Sample leases  →  Filter  →  Edit Fields (Set)
Enter fullscreen mode Exit fullscreen mode

The sample data lives inside the workflow, so you can rebuild it with no accounts connected. In a real office the second node would be Google Sheets or Airtable, and an email or Slack step would follow. The middle two nodes stay the same.

The data

Six items, one per lease:

tenant unit status days_left rent
Dana Whitfield 2B Active 21 1850
Marcus Oyelaran 4A Active 143 2100
Priya Raman 1C Active 48 1620
Tom Becker 3D Notice given 30 1975
Elena Soto 5A Active 59 2240
Grace Lindqvist 2D Active 212 1790

The rule: send a renewal offer to every Active lease that ends in 60 days or less.

If you want to paste the sample in yourself, a Code node returning this does the job:

return [
  { tenant: 'Dana Whitfield', unit: '2B', status: 'Active', days_left: 21, rent: 1850 },
  { tenant: 'Marcus Oyelaran', unit: '4A', status: 'Active', days_left: 143, rent: 2100 },
  { tenant: 'Priya Raman', unit: '1C', status: 'Active', days_left: 48, rent: 1620 },
  { tenant: 'Tom Becker', unit: '3D', status: 'Notice given', days_left: 30, rent: 1975 },
  { tenant: 'Elena Soto', unit: '5A', status: 'Active', days_left: 59, rent: 2240 },
  { tenant: 'Grace Lindqvist', unit: '2D', status: 'Active', days_left: 212, rent: 1790 },
].map((json) => ({ json }));
Enter fullscreen mode Exit fullscreen mode

Step 1: Two conditions joined by AND

Add a Filter node ("Keep only items matching a condition").

Each condition has three parts: a value from the item, a comparison, and what to compare it with.

  1. Drag days_left from the INPUT panel onto the first box. n8n writes {{ $json.days_left }} for you.
  2. Because the field is a number, n8n offers number comparisons. It defaults to is equal to. Change it to is less than or equal to and type 60.
  3. Click Add condition. Drag status onto the new first box. Leave is equal to and type Active.

The two rows are joined by AND, so an item has to pass both. Switch to OR when passing either one is enough.

In the workflow JSON, those conditions look like this:

"conditions": [
  { "leftValue": "={{ $json.days_left }}", "rightValue": 60,
    "operator": { "type": "number", "operation": "lte" } },
  { "leftValue": "={{ $json.status }}", "rightValue": "Active",
    "operator": { "type": "string", "operation": "equals" } }
],
"combinator": "and"
Enter fullscreen mode Exit fullscreen mode

Note the type on each operator. That detail comes back below when a filter returns nothing.

Step 2: Open the Discarded pile

Click Execute step. The output has two piles: Kept and Discarded.

Kept has three items: Dana, Priya and Elena.

Don't stop there. Open Discarded and check each reason:

  • Marcus: 143 days left. Correct.
  • Grace: 212 days left. Correct.
  • Tom: only 30 days left, yet dropped. Also correct, because his status is Notice given. He's leaving, so he doesn't get an offer.

Tom is the reason this check matters. If you had built the filter on days_left alone, he'd get a renewal offer for a unit he's already moving out of. If you'd typed active in lowercase with case sensitivity on, everyone would be in Discarded. Either way, the Discarded pile shows you in one click. A filter that silently drops the wrong rows is worse than no filter.

Step 3: Edit Fields (Set) keeps only what you name

Add Edit Fields (Set) after the Filter.

  1. Drag tenant onto Drag input fields here. n8n names the field and fills in the value.
  2. Do the same with unit.
  3. Add Field, name it reminder, and set the value to:
Lease for unit {{ $json.unit }} ends in {{ $json.days_left }} days. Send {{ $json.tenant }} the renewal offer.
Enter fullscreen mode Exit fullscreen mode

Click Execute step. Three items come out with three fields each:

{
  "tenant": "Dana Whitfield",
  "unit": "2B",
  "reminder": "Lease for unit 2B ends in 21 days. Send Dana Whitfield the renewal offer."
}
Enter fullscreen mode Exit fullscreen mode

status and rent are gone. Edit Fields builds a new item from the fields you set and leaves everything else out. That's what you want before an email or Slack step: nothing extra leaks into the message.

When you want to add one field and keep the rest, turn on Include Other Input Fields.

(Edit Fields used to be called Set. Older tutorials and template JSON still use that name, and the node type is still n8n-nodes-base.set.)

Why does my Filter return no items?

Almost always one of these:

  1. Type mismatch. The field is text ("60") and the comparison is a number one. Data from spreadsheets and CSVs often arrives as strings. Turn on Convert types where required in the Filter's options.
  2. Case. Active vs active. Check the spelling against the INPUT panel, or turn off case sensitivity.
  3. Wrong field name. Dragging from INPUT avoids typos; typing an expression by hand invites them.

In all three cases, the Discarded pile shows you the values n8n actually compared.

Filter or If?

  • Filter drops what fails. Use it when the rest of the workflow only cares about the matches.
  • If keeps both sides and sends them down two paths (true and false). Use it when the other rows need steps of their own.
  • Switch routes to more than two paths, with a fallback output.

And when a rule gets too awkward for conditions, a few lines in a Code node will do it.

Checklist

  • [ ] Conditions built by dragging fields from INPUT
  • [ ] Number fields use a number comparison
  • [ ] AND vs OR chosen on purpose
  • [ ] Discarded pile opened and each reason checked
  • [ ] Convert types on for spreadsheet data
  • [ ] Edit Fields keeps only the fields the next step needs

Practice it

This is a free step-by-step lesson where you do each click yourself in a practice copy of n8n (26 steps, about 7 minutes, no account), with the workflow JSON to import: n8n: Keep Only the Rows That Matter with Filter and Edit Fields.

Top comments (0)