Skip to content

fix(statistical): COUNT does not count dates, so COUNT(MAX(<date range>)) is 0 #780

Description

@hhimanshu

What

COUNT matches only Value::Number and falls to _ => {} for everything else, so it does not count a date.

=COUNT(DATE(2020,1,1))    truecalc: 0    Sheets: 1

Google Sheets counts dates — they are numbers with a display format.

Why it is worth filing now

It has become newly reachable. Once MAX/MIN/MAXA/MINA return a date-typed result for a date range (the captured Sheets behaviour), every extreme taken over a date column flows into this:

=COUNT(MAX({DATE(2020,1,1),5}))    before: 1    after: 0

Verified on both builds. Same flip for MIN, MAXA, MINA.

Failure scenario: =COUNT(MAX(Orders!A:A)) over a date column returned 1 and now returns 0. A "how many results did I get" guard silently becomes zero — a believable wrong answer rather than a visible error.

The root cause is pre-existing and independent of that change; the change only exposes it.

The catch-all is still live

A reviewer added a probe variant to Value and ran cargo check on both sides. On the branch that types the extremes, max/min/maxa/mina are all flagged non-exhaustive — those four were deliberately refactored away from catch-alls so a new variant is a compile error. statistical/count/mod.rs is flagged on neither side: its _ => {} silently absorbs any variant added in future.

That is the same shape as a defect already fixed once in this area, where a catch-all swept Value::Date into a "has content" flag and turned a visible #REF! into a believable 0.

Scope

  • Probe first. =COUNT(DATE(2020,1,1)), =COUNT(<a date range>), dates mixed with numbers, COUNTA for comparison, and the same for any sibling reducer sharing the shape. Do not fix from reasoning — "Sheets counts dates" is widely believed and this repo forbids self-confirmed values. The conformance-fixtures pipeline now has working range-based probes for the statistical functions.
  • Replace the catch-all with an explicit match so a future Value variant is a compile error rather than a silent zero.
  • Prove nothing else moved with a differential against main, reporting the case count. COUNT is used everywhere.

Acceptance criteria

  • Captured rows for COUNT over dates, and for any sibling with the same gap
  • COUNT agrees with the capture
  • The catch-all is gone; a new Value variant fails to compile rather than being silently uncounted
  • Differential against main shows no unrelated input changed, with the case count reported
  • CI green

Related

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions