Skip to content

fix(core): use the range_calendar period for prior-period comparisons in filters=[] - #3351

Open
straw-hat-gupta wants to merge 2 commits into
evidence-dev:mainfrom
straw-hat-gupta:fix/3335-range-calendar-comparison
Open

straw-hat-gupta wants to merge 2 commits into
evidence-dev:mainfrom
straw-hat-gupta:fix/3335-range-calendar-comparison

Conversation

@straw-hat-gupta

Copy link
Copy Markdown

Fixes #3335

Summary

A big_value or table comparison with compare_vs="prior period" or "prior year" showed 0% when its period came from a range_calendar in filters=[...] instead of date_range=. The comparison had no date_range to shift, and the calendar's predicate was also applied to the comparison CTE, so the "prior" period was the current one again.

A comparison without its own date_range now borrows the period of the first date filter in filters=[...], and that filter's predicate is left out of the comparison CTE, so the shifted range selects the prior period. Other filters still apply to both periods.

Changes

  • Filter.svelte.ts: new comparisonDateRange(), undefined by default.
  • RangeCalendarFilter: returns the active period on value_column. It returns nothing for a range with no period to shift: open-ended (from ...) or unbounded "all time".
  • sql-options.ts: borrowFilterDateRanges gives those comparisons the borrowed date_range and a cteFilterSql without the date filter.
  • build-comparisons.ts: the comparison CTE and its grouping use cteFilterSql when it is set.

An explicit date_range on the component still takes precedence and behaves as before. The main query and target/benchmark comparisons are unchanged.

One assumption: the filter and the query resolve relative presets like "last 7 days" against the same anchor date. They do today, because both use computedDefaultDateRangeEnd or today (Query.maxDateQuery returns undefined). If max-date detection is re-enabled, the prior period could stop being adjacent to the current one.

Not covered: period_selector with value_column has the same 0%. It would lend fixed dates, which shift by day count (March would compare against Jan 29 - Feb 28) rather than by month or quarter, so it needs its own change. Happy to follow up.

Testing

  • New common/sql-options.filter-comparisons.test.ts runs the generated SQL on chdb with real range_calendar and dropdown filters. It covers prior period and prior year, other filters kept on both periods, an explicit date_range left alone, and tables with a region or daily date dimension. Calendar results match date_range= row for row.
  • RangeCalendarFilter.svelte.test.ts: unit cases for comparisonDateRange(), including an open-ended range.
  • 7 of the 8 new tests fail on main (for example the prior value is 161, the current value, instead of 107). The explicit date_range case passes on both.
  • TZ=UTC pnpm test: core 4224 passed, cli 423 passed. pnpm check: 0 errors. pnpm cli:build succeeds.

straw-hat-gupta and others added 2 commits October 25, 2026 02:06
A big_value or table comparison with compare_vs "prior period" or
"prior year" that takes its period from a range_calendar in filters=[...]
compares the current period with itself and reports 0% (evidence-dev#3335). On a
table with a date dimension the same bug shows as missing prior values.

The cases run the generated SQL on chdb against inline values() data,
with real Filters (range_calendar, dropdown), and assert whole result
rows. RangeCalendarFilter also gets unit cases for the range it lends to
comparisons, including none for an open-ended range.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… in filters=[]

A big_value (or table) with comparison={ compare_vs="prior period" } and
its period coming from filters=["dates"] instead of date_range= reported
a flat 0.00%. The calendar's predicate was applied to the comparison CTE as
well, so the "prior" period was the current one again.

Comparisons with no date_range of their own now borrow the bounded period
of the first date filter in filters=[] (Filter.comparisonDateRange,
implemented by RangeCalendarFilter), and that filter's predicate is left
out of the comparison CTE so the shifted range selects the prior period.
Open-ended calendar ranges lend nothing. Other filters still apply to both
periods; an explicit date_range is untouched.

Fixes evidence-dev#3335

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

@straw-hat-gupta is attempting to deploy a commit to the Evidence Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

big_value comparison silently reports 0.00% when the period comes from a range_calendar filter

1 participant