PostHog / PostHog/posthog

Numerical property aggregations include events where the property is not set (missing values treated as 0)

Open
#52,845 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
39.9k
Forks
3.4k
Avg merge
6h 51m
Merged PRs (30d)
232

Description

Bug Description

Bug: Numerical property aggregations (median, average, etc.) include events where the property is not set, treating missing values as 0

Description
When computing a median (or other numerical aggregations) on an event property, PostHog includes events where that property is not set, treating the missing value as 0. This produces incorrect results and is misleading.

Expected behavior
Aggregations on a property should only consider events where that property is explicitly set — similar to how SQL's AVG() or MEDIAN() ignore NULLs automatically.

Actual behavior
Events where the property is absent are included in the aggregation, effectively counted as 0. This skews the result.

Reproduction steps

Create a Trends insight with a median aggregation on a numerical event property (e.g. pictures_deleted on event sorting:swiper=end)
Note the median value (e.g. 43)
Add a filter: pictures_deleted is set
The median changes significantly (e.g. to 25.5), confirming that events without the property were included in step 2

Workaround
Manually adding "is set" as a filter on each series that uses a numerical aggregation.

Impact
Any insight using numerical property aggregations (median, average, sum, etc.) without an explicit is set filter will silently produce incorrect results.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in a Trends insight using a median aggregation on a numerical event property, then compare the result with and without an “is set” filter. Trace the aggregation behavior for absent properties across median, average, and sum; done means missing properties are excluded automatically and the workaround filter no longer changes the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
analytics, data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.