Turn a business question into a bounded analytical query
A fleet dashboard reads a year of vehicle events to show yesterday’s delays.
Turn a business question into a bounded analytical query
A fleet dashboard reads a year of vehicle events to show yesterday’s delays. Define the numerator, denominator and time zone first, then bound the scan and test the result on a hand-checkable subset.
The speaker explains why a partition predicate plus selecting only required columns can reduce the bytes processed. The next lesson moves exploratory work into a notebook.
Work through the decision
Depot North reports 8 late trips out of 10 and South reports 20 out of 100. What is the region’s late-trip rate?
Check your reasoning
There are 28 late trips among 110, about 25.5%. The average of the two percentages is 50% and gives a ten-trip depot the same influence as a hundred-trip depot.
Decisions and tradeoffs
- Partition pruning with column projection
- Filter on a usable partition key and select only the necessary fields. Inspect the dry-run estimate before and after the change.
- Window function over a defined partition
- Use a window to rank or compare rows within each entity while preserving detail and choosing an explicit order.
- Group-level rate from aggregate counts
- Sum the numerator and denominator at the requested grain before taking their ratio; handle a zero denominator explicitly.
- Notebook over an aggregated extract
- Use SQL to reduce the data first, then use a managed notebook to explore and visualize an affordable, representative result.
- Explicit business-day boundary
- Derive the reporting date in the business time zone and define half-open intervals to avoid missing or double-counting rows at midnight.
Inspect a small GoogleSQL result
In a BigQuery query editor, use a small inline sample to check the grain and division before scanning a production table.
WITH depots AS (
SELECT 8 AS late, 10 AS trips UNION ALL
SELECT 20, 100
)
SELECT ROUND(100 * SAFE_DIVIDE(SUM(late), SUM(trips)), 1) AS late_pct
FROM depots;
The single result is 25.5. Run a dry run on the production version with its partition predicate and required columns, then inspect processed bytes in the completed job.
Practice each guide skill
Work through these exercises in the order of the published guide. The checklist numbers are local references.
- Write a GoogleSQL query over one partition with an explicit business grain, then compare the dry-run estimate with a broad query.
- Fetch a bounded aggregate into a managed Jupyter notebook such as Colab Enterprise, plot a distribution and inspect missing categories.
- Define the late-trip rate including denominator and reporting zone. Compare the aggregate with a hand-calculated pair of branches.
Official objectives for this lesson
Related lesson · Choose the grain before aggregating
Turn a business question into a bounded analytical query quiz
Answer 3 questions. Check each answer for an explanation.