BigQuery’s daily active-user average can leave out days with no events
Give generated SQL a calendar to average over. But count a missing day as zero only when you know the event feed was complete.
Ask an analytics agent for average daily active users over three calendar days. Give it a complete event feed with three distinct users on Monday, no events on Tuesday, and one distinct user on Wednesday. If it groups the event rows by date and averages the two resulting counts, it returns 2. The requested calendar-day average is 4 ÷ 3, about 1.33. The query can run successfully and count each observed day correctly while still answering a different question: how many users were active on days with recorded activity?
Start with the dates, not the events
BigQuery’s GENERATE_DATE_ARRAY generates dates at one-day intervals by default and includes both endpoints. Use those dates as the rows the query must preserve. Aggregate distinct users once per reporting date, then attach those counts to the calendar. Under the explicit assumption that every date has complete telemetry, a day with no matching event count is zero.
-- event_date is already defined in the reporting time zone.
-- Both endpoint parameters are DATEs and are inclusive.
WITH calendar AS (
SELECT day
FROM UNNEST(GENERATE_DATE_ARRAY(@start_date, @end_date)) AS day
), daily AS (
SELECT event_date AS day, COUNT(DISTINCT user_id) AS active_users
FROM `project.dataset.events`
WHERE event_date BETWEEN @start_date AND @end_date
GROUP BY event_date
)
SELECT COUNT(*) AS calendar_days,
AVG(COALESCE(daily.active_users, 0)) AS avg_daily_active_users
FROM calendar
LEFT JOIN daily USING (day);
This is a worked example, not a live BigQuery run. The extra calendar_days output gives reviewers a denominator to check against the requested date range. This query does not calculate distinct users across the entire period: someone active on Monday and Wednesday belongs in each day’s count.
Test a quiet day and a broken feed separately
Use the same three-day fixture twice. First mark Tuesday’s feed complete: expect three counted calendar days and about 1.33 daily users. Then mark Tuesday’s feed incomplete: do not accept 1.33 as a confirmed full-period average. If a separate ingestion record can identify incomplete dates, have the agent surface that status; if it reports an observed-days average instead, label it as such and show its denominator. The event table alone cannot distinguish a genuine zero from an outage in this fixture.
sources
- Google Cloud: GENERATE_DATE_ARRAYdocs.cloud.google.com
- Google Cloud: AVGdocs.cloud.google.com
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026