top of page

Should a Reporting Threshold Filter Individual Rows or Whole Groups?

Oct 26
3 min read

A manager asks for teams that completed more than ten tasks. A report developer sees the number ten and adds a filter to the task table. The query runs, yet the resulting list is wrong. The threshold describes the team's combined work, not an attribute of each task.


This is a useful review question whenever a dashboard uses words such as “teams with”, “customers whose total”, or “projects averaging”. First establish which records are eligible. Then establish which grouped results should be shown. Keeping those decisions separate makes both SQL and the report explanation easier to inspect.


Write the two rules in plain language


A row rule might be “include tasks completed during the reporting period”. A group rule might be “show only teams with more than ten included tasks”. The first decides what contributes to the count. The second decides which calculated counts appear.


PostgreSQL's aggregate tutorial distinguishes WHERE, which filters input rows before grouping, from HAVING, which filters grouped results. An aggregate condition such as COUNT(*) > 10 belongs at the grouped-result stage.


Use this distinction to review intent, rather than mechanically moving every condition into HAVING. A condition on a source field can change the evidence entering the calculation, even if the final output still contains the same team names.


Work through a small report by hand


Illustrative example: three teams


Cedar has twelve completed tasks and four open tasks. Birch has eight completed tasks and twenty open tasks. Elm has exactly ten completed tasks and no open tasks. The requested report includes only Cedar, with twelve.


An illustrative query shape is SELECT team_id, COUNT(*) AS completed_tasks FROM tasks WHERE status = 'complete' GROUP BY team_id HAVING COUNT(*) > 10. A real report would also include the agreed completion-date boundary and any other eligibility rules.


If the status filter is omitted, Birch may appear because its open work is included. If the group rule uses >= rather than >, Elm appears too. These are business-definition errors even when the SQL is syntactically valid.


Change one fixture value at a time


Give Elm an eleventh completed task in a separate fixture. It should cross the threshold only after the qualifying count changes. Add an ineligible task to Cedar and confirm that its count remains twelve.


Testing these changes separately helps identify the specific rule responsible for an unexpected result. A large random dataset is much harder to reason about because several causes can change at once.


Be explicit about empty groups


A team with no eligible tasks may disappear when the query starts from eligible task rows. If the business also wants zero-count teams, that is an additional requirement, often involving a separate team list and an appropriate join.


Do not claim that switching WHERE to HAVING solves zero-row reporting. Decide whether the report is a list of qualifying activity groups or an inventory of every team, including those with no activity. These are legitimate but different outputs.


Also distinguish a missing team identifier from a named team with zero completed tasks. Resolve unknown ownership as a data-quality issue instead of quietly assigning it to an arbitrary team.


Review the denominator as well as the threshold


An average or rate requires more care than a count. Filtering out incomplete records before calculating a completion rate may remove precisely the records needed in its denominator. Write down the numerator population, denominator population and grouping key before approving that query.


A useful review note contains the row-eligibility sentence, grouping fields, aggregate expression, comparison operator and expected boundary cases. Include the units: a threshold of ten minutes is not ten records.


Keep a reproducible acceptance example


Retain the Cedar, Birch and Elm fixture with the report change. Record the expected team names and totals, not merely that the query “passed”. Recheck the fixture when the reporting period, status vocabulary or join structure changes.


The companion guide on writing a metric definition card helps establish those business meanings. For a FutureOS discussion, bring the two plain-language rules and the smallest dataset that demonstrates the disagreement. They give collaborators something concrete to resolve.


Editorial note


Editorial note: This article was prepared with AI assistance. Primary sources and the linked FutureOS article inventory were checked on October 26, 2026. Examples are illustrative and are not customer results. The current FutureOS introduction describes the project as being in prelaunch; this guide does not assert that a particular product feature, integration or service is available. The procedures are practical proposals to adapt and test in your own setting. No independent expert review is claimed. Start with a specific question, your relevant constraints and a small example of the result you need.


Comments


Commenting on this post isn't available anymore. Contact the site owner for more info.
bottom of page