Keeping missing metrics distinct from zero in an n8n reporting helper

I’m testing the measurement part of the local helper store used alongside my self-hosted n8n publishing project. The case is a metrics collection run that gets a real zero for one field and no value for others.

The failure I want to avoid is a later reporting step silently turning “not measured” into “no engagement”.

Synthetic input and observed result

Today’s focused local test supplied views: 4, posts_count: 1 and responses_from_others: 0, while omitting likes and followers gained.

Field Stored result
responses_from_others 0
likes null
followers_gained null

The normalisation in my custom helper is equivalent to:

const storedValue = inputValue ?? null;

This preserves a measured zero. I keep unavailable values as null through storage rather than filling them with zero for the report.

The retry check

The same test reopens the file-backed store and submits the exact same observation again. The helper returns duplicate: true.

The observation identity in this implementation is:

channel + publication URL + source + captured_at

A genuinely later collection needs its own capture time. Replaying a collection should preserve the original capture time; creating a new timestamp during a retry would make it a different observation under this rule.

For a workflow calling this helper, my intended boundary is: retain the observation and capture time, write it, and retry that same observation after an uncertain response. That workflow-level uncertain-response path is not what today’s test exercised.

What this actually verifies

The single focused test passed: missing fields stayed null, a known zero stayed zero, and an identical observation was recognised after reopening the store. It uses synthetic data and my own helper code; it does not verify live platform analytics, n8n’s built-in storage, concurrent collectors, or end-to-end publishing.

My next check is how an unavailable metric is displayed downstream, so a chart or spreadsheet does not undo the storage distinction.

If your n8n reporting workflow writes to Sheets or a database, how do you distinguish a measured zero from a metric the source did not provide?

Keeping null all the way through storage is the right call. Two things that bit me on a similar reporting step:

1. Aggregation is where “not measured” quietly becomes zero. If a later step sums or averages likes across posts, sum only the measured values and carry a count of how many were null, so a weekly total reads like “likes: 12 (2 of 5 posts not measured)” instead of looking complete. Test whatever node does the rollup (Summarize, Code with reduce, a SQL step) with a null in the input, because they don’t all treat it the same way.

2. Store a reason next to each null. “not offered by this platform” and “API call failed” are both null, but one will never fill in and the other should be retried on the next collection. Without the reason the report can’t tell them apart.

On the identity key, I’d normalize the publication URL before using it (strip tracking params and trailing slashes). Otherwise the same post can turn into two observations when one run gets a share URL with extra query params.

Good discipline getting this right at the storage layer — most people only discover the problem when a dashboard lies to a client.

Your ?? null is the correct normalization, and it’s worth being explicit about why, because the common “simplification” destroys your measured zeros. inputValue || null — or if (!inputValue) — treats 0, "" and false as missing. The day someone copies your helper and rewrites it with ||, your responses_from_others: 0 silently becomes “not measured”. I’d put a comment in the Code node saying exactly that, and keep the deliberate-zero regression test you already have.

Two production details that bit me downstream of a setup like this:

1. Sheets doesn’t round-trip null. The Google Sheets node writes null as an empty cell, and reading it back gives you "", not null. So your read-log-then-compare step needs value === "" ? null : value on the way back in, or your retry/dedupe identity silently changes shape between write and read. Postgres is cleaner — a real NULL survives storage — but then SUM() over all-null rows returns NULL (not 0), and COUNT(col) skips nulls while COUNT(*) doesn’t. Decide which behavior you want per metric and encode it in the query, not in the chart.

2. Surface the reason where the human looks. Storing a reason next to each null (as nigelyong suggested — not_offered_by_platform vs api_failed) is half the job. In my reporting workflows I also write a companion status column, e.g. likes_status: "not_available:api_failed", and the report template renders missing as “—” and zero as “0”. The failure mode you’re guarding against isn’t storage, it’s rendering: most chart tools draw null as a gap and 0 as a data point, but a spreadsheet SUM treats a blank as 0. State the rendering rule next to the data contract so nobody re-derives it per report.

One more on your identity key: channel + publication URL + source + captured_at is fine, but normalize the URL before it becomes an identity — strip utm params, lowercase the host — or you’ll get two “different” observations for the same post the first time someone shares it with tracking params attached.

Good point! Keeping zero and missing data separate is very important. I also work with n8n and PostgreSQL, and this is a useful lesson for building reliable workflows. Thanks for sharing!

Thanks, @nigelyong and @waqasahmedwaseer. The aggregation boundary is a useful next check. For a small synthetic test matrix, I’d use:

  • [0, null, 4]: measured sum 4, measured count 2, missing count 1.
  • [null, null]: no measured total, rather than reporting a measured zero.
  • [0, 0]: a measured total of 0.

That makes completeness visible alongside the total. My existing test only covers the local file-backed store; it does not verify a Sheets round-trip, SQL rollup or dashboard rendering. The cases above are proposed checks, not new test results. A missing-value reason and a provider-aware URL normalization rule also need their own contract and tests before I can call them implemented. Thanks as well, @Shital_Katre.

Thanks, Mohammad! I agree that showing data completeness alongside totals is important. It helps prevent missing values from being mistaken for zero. The proposed test cases are a useful way to check this clearly.

Preserving 0 and null separately at storage is the right boundary to protect.

The next failure point is probably the reporting layer. A spreadsheet formula, chart or summary step can silently turn a blank or null into zero again, even though the helper stored it correctly.

For the downstream test, I’d use three states side by side: a measured zero, a positive value and an unavailable value. The report should make the unavailable one visibly different rather than simply leaving the reader to interpret an empty cell.

I’d also keep the collection status or reason alongside the value, so “source did not provide this metric” remains distinguishable from “collection failed.”

1 Like