Skip to content

Add a date range filter to analytics, in the engine and the UI #177

Closed

Description

@imshashank

There is no way to ask Orbit a question about a period of time. The analytics page reports on all issues that have ever existed in the workspace, and the only control on it is a toggle between counting issues and counting points.

"How did we do last quarter" is the most common question anyone asks an analytics page, and Orbit cannot answer it.

This is missing at every level, not just in the UI, so it has to be added at every level.

The engine has no concept of a date range

chartRequestSchema in packages/core/src/analytics/schemas.ts is:

export const chartRequestSchema = z.object({
  scope: analyticsScopeSchema,
  xAxis: chartDimensionSchema,
  segment: chartDimensionSchema.optional(),
  measure: measureSchema,
});

No dates. scopeClause in distribution.ts filters on organisation, archived state and visible teams, and nothing else. scopeSeries computes its own bounds from min(created_at) to the last completion, so it always covers all of history.

What to build

In the engine, packages/core/src/analytics/:

  1. Add an optional range to chartRequestSchema and to the input types. Two ISO dates, inclusive start, exclusive end, both optional so an absent range keeps today's behaviour.
  2. Decide and write down which date the range filters on. This is the part that matters and the part that is easy to get wrong. A distribution by assignee over "last month" could reasonably mean issues created last month, issues completed last month, or issues that were open at any point last month. They give very different numbers. Our suggestion is that the range filters on completed_at for anything measuring throughput and on created_at for anything measuring intake, and that the UI says which one it is doing. Argue for something else on this thread if you disagree, but the answer has to be explicit and documented, not implied by the SQL.
  3. Thread the range through scopeClause, buildChart, workDistribution, stateGroupBreakdown and scopeSeries.
  4. scopeSeries should use the range as its bucket bounds when one is given, instead of deriving bounds from the data. Pick the bucket size from the range width: days for a range under about six weeks, weeks under about a year, months beyond that.

In the UI, apps/web/src/features/analytics/:

  1. A range control in the page header next to the existing MeasureToggle. Presets carry almost all the value: last 7 days, last 30 days, this quarter, last quarter, this year, all time. A custom range picker is worth having but is not the first slice.
  2. Put the range in the URL the way measure already is, so a range is linkable and survives a refresh.
  3. Saved analytics views should store the range. See savedAnalyticsViewCreateSchema in schemas.ts and the saved_analytics_view table.

Watch out for

  • The empty state currently says "No issues in range" in breakdown-section.tsx even though there is no range. Once there is one, that string is finally true, and it should say which range.
  • Every existing caller passes no range. Keep the parameter optional so nothing breaks, and let the page opt in.
  • Indexes. issue_team_created_idx and issue_org_active_idx exist and cover some of this. Check the plan for a range filtered distribution before assuming it is fine.

Tests

packages/core/tests/analytics/ has fixtures in test-fixtures.ts for inserting issues at specific timestamps. Add cases that assert an issue outside the range is excluded, and one that pins the created versus completed decision so a later refactor cannot quietly flip it.

This is one of the highest value changes on the analytics milestone. Comment before starting so we can agree the created versus completed question first.

Activity

  1. added
    enhancement
    help wanted
    needs design
    p1 high
    area: analytics
    on Aug 8, 2026
  2. moved this to Needs design in Orbit roadmapon Aug 8, 2026
  3. added
    size: large
    points: 8
    on Aug 8, 2026
  4. imshashank commented on Aug 8, 2026

    @imshashank
    ContributorAuthor

    Related to #179, which is the performance issue on the same page.

    The bounding this issue adds to scopeSeries removes a meaningful part of the cost measured there, so #179 explicitly defers date range work to this issue. Do not solve caching here, and do not solve bounding there.

    The chart builder in #182 and the scope picker in #178 both need to inherit whatever range control this issue introduces, so put the range in the URL and in the saved view payload rather than in component state.

  5. imshashank commented on Aug 15, 2026

    @imshashank
    ContributorAuthor

    Done, closing. This landed with the planning cockpit in #309, in a different shape than the issue proposed.

    A reporting range now exists at every level this issue asked for:

    • Engine. analyticsRangeSchema in packages/shared/src/validators/analytics.ts carries auto, active_sprint, previous_sprint, last_30_days, last_90_days, all_time, and a custom range with validated from/to. It sits on analyticsQuerySchema alongside lens, measure, compare, filter and focus.
    • Resolution and bucketing. packages/core/src/analytics/filter.ts resolves the range against a reporting timezone and derives the bucket granularity from the range width, capped at MAX_BUCKETS. Series no longer derive their own bounds from min(created_at), which was the specific complaint in point 4.
    • UI. apps/web/src/features/analytics/date-range-picker.tsx, in the toolbar next to the measure control, with the presets above plus a custom from/to form.
    • URL. query-state.ts serialises the whole query, so a range is linkable and survives a refresh.
    • Saved views. savedDashboardConfigSchema in packages/core/src/analytics/schemas.ts stores the full analyticsQuerySchema, range included.

    Two differences from the plan here, both deliberate and worth recording:

    1. The range was not added to chartRequestSchema. That schema and POST /api/analytics/chart still exist unchanged, and the range lives on the new lens query model instead. That leaves buildChart without a range, which matters for A chart builder over the dimensions the engine already supports #182.
    2. The created-versus-completed question this issue asked to pin down is answered per metric rather than per range, in formulas() in packages/core/src/analytics/sprints.ts, and surfaced on the sprint lens. So the answer is explicit and in the payload, which was the requirement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: analyticsenhancementhelp wantedneeds designp1 highpoints: 8size: large

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions