Forecasting and Time-Series Analysis Questions
Analyzing and projecting data that moves over time. Covers trend and seasonality decomposition, forecasting approaches, demand modeling, and anomaly detection on time series. Emphasizes reasoning about baselines, drivers, and forecast reliability.
Write a SQL query to compute month-over-month revenue growth and seasonally adjusted growth per product given a daily_revenue table with schema (product_id INT, revenue_date DATE, revenue DECIMAL). Describe any assumptions and how you would handle products with sparse history or partial months.
Sample Answer
Direct answer
Computing seasonally-adjusted growth in SQL means dividing each period's revenue by a seasonal index before comparing period over period; the SQL itself is straightforward window-function work, but the seasonal index needs enough HISTORY (multiple years) to be estimated reliably, which is a real limitation this exercise surfaces directly.
Structured elaboration and worked example (executed)
Against a synthetic daily_revenue table (6 months of daily rows for one product, rolled up to monthly), a query computing month-over-month growth and a naive seasonally-adjusted figure:
WITH monthly AS (
SELECT product_id, substr(revenue_date,1,7) AS ym, SUM(revenue) AS total_revenue
FROM daily_revenue GROUP BY product_id, ym
),
with_lag AS (
SELECT *, LAG(total_revenue) OVER (PARTITION BY product_id ORDER BY ym) AS prev_total
FROM monthly
),
seasonal_index AS (
SELECT CAST(substr(ym,6,2) AS INTEGER) AS month_num,
AVG(total_revenue) AS month_avg,
(SELECT AVG(total_revenue) FROM monthly) AS grand_avg
FROM monthly GROUP BY month_num
)
SELECT w.product_id, w.ym, w.total_revenue, w.prev_total,
ROUND(100.0 * (w.total_revenue - w.prev_total) / w.prev_total, 2) AS mom_growth_pct,
ROUND(w.total_revenue / (si.month_avg / si.grand_avg), 2) AS seasonally_adjusted_revenue
FROM with_lag w JOIN seasonal_index si ON si.month_num = CAST(substr(w.ym,6,2) AS INTEGER)
ORDER BY w.ym;
Executed against 6 months of synthetic daily data for product 1 (seed=1, Jan-Jun 2024, revenue = 1000 + 50sin(2pi*day/30) + N(0,30) per day, rolled up to monthly), the raw output showed month-over-month growth swinging from +7.23% to -5.97%, but the seasonally_adjusted_revenue column came out to the SAME value (30,402.55) for every single month. This is a real, informative artifact rather than a bug in the intent: with only ONE observation per calendar month in the history (6 months = 6 distinct calendar months, no repeats), the "seasonal index" for each month is trivially just that month's own value, so dividing by it exactly cancels out - you cannot separate trend/level from seasonality with only one cycle of data. A seasonal index needs MULTIPLE years so each calendar month has more than one historical observation to average.
- Handling sparse history or partial months: for a product with less than a full month of data (a mid-month launch), either exclude that partial month from month-over-month comparisons entirely (comparing a partial month to a full prior month is misleading) or explicitly annotate the day-count and consider a run-rate (extrapolated) comparison instead; for products with less than 2 full years of history, either fall back to an unadjusted comparison with a caveat, or borrow a seasonal index from a comparable product/category rather than attempting to estimate one from too little of the product's own data.
Trade-offs & pitfalls
The seasonal-index approach shown here is the simplest possible naive method and genuinely requires several years of history to be trustworthy - shipping a "seasonally adjusted" number computed from under a year of data (as this executed example deliberately demonstrates) can look legitimate while being mathematically degenerate. A production version would either use a proper STL/classical decomposition fit on multi-year history, or explicitly disable the seasonal adjustment and label the number as raw growth until enough history exists.
Explain and compare straight-line (linear) growth projections and percentage-based compound growth projections. Provide formulas for both, discuss when each is appropriate for metrics such as revenue or headcount, and highlight limitations (sustainability, seasonality, constraints).
Sample Answer
Direct answer
Linear (straight-line) growth adds a fixed absolute amount each period: yt=y0+g⋅t; compound growth multiplies by a fixed percentage each period: yt=y0⋅(1+r)t. Linear projections are appropriate for metrics with a genuinely fixed absolute increment (limited or plateauing growth); compound projections are appropriate for metrics that grow proportionally to their current size (viral/network-effect growth, revenue compounding on an expanding base), and both break down badly once extrapolated far past any plausible constraint.
Structured elaboration
- Linear: yt=y0+g⋅t, where g is a fixed absolute amount added each period. Appropriate for headcount growing by a planned, fixed number of hires per quarter, or a metric expected to plateau toward a fixed increment rather than accelerate.
- Compound: yt=y0⋅(1+r)t, where r is a fixed PERCENTAGE growth rate each period. Appropriate for revenue or user-base metrics where growth genuinely scales with the current size (a larger customer base referring proportionally more new customers, compounding month over month).
- When each is appropriate: plot recent history and check whether the ABSOLUTE period-over-period change has stayed roughly constant (favors linear) or whether the PERCENTAGE period-over-period change has stayed roughly constant while the absolute change has been growing (favors compound) - this is the same diagnostic used to distinguish additive from multiplicative seasonality, applied to trend instead.
- Limitations:
- Sustainability: compound growth extrapolated far enough always implies an absurd, physically-impossible outcome eventually (a metric can't compound at 20%/month forever without exceeding any plausible market size) - a compound projection is only defensible over a horizon short enough that this ceiling isn't yet binding, or it needs to be replaced with a saturating (logistic/S-curve) growth model that explicitly bends toward a ceiling.
- Seasonality: neither formula accounts for within-year seasonal variation on its own - a naive compound-growth trend line fit through seasonally-uneven data can badly misjudge the underlying growth rate unless the data is seasonally adjusted first or seasonality is modeled explicitly alongside the trend.
- Constraints: linear projections extrapolated far past history similarly ignore any real capacity, market-size, or resource constraint that would eventually cap growth.
Worked example
A team growing headcount by a planned, fixed 5 hires/quarter is well-represented by a linear projection; a subscription product growing 8%/month off compounding word-of-mouth referrals is better represented by compound growth in its early phase - but extrapolating that 8%/month compound rate 3 years forward would (absurdly) predict a user base many times the addressable market, which is exactly the signal that a saturating growth-curve model, not continued naive compounding, is the right tool once the addressable market's scale becomes a real constraint.
Trade-offs & pitfalls
The most common mistake with either formula is treating a SHORT window's observed growth rate as a stable long-run constant and extrapolating it far past the horizon that assumption can support - always state explicitly how far forward a linear or compound projection is being trusted, and flag the point at which a more sophisticated (saturating, or fully model-based) approach becomes necessary.
Describe methods to handle temporal aggregation mismatch where sales are recorded weekly but business requires daily forecasts. Discuss the disaggregation techniques you would consider and how you'd choose among them, how to propagate uncertainty from aggregated to disaggregated forecasts, and how to evaluate disaggregated predictions without daily ground truth.
Sample Answer
Direct answer
When sales are recorded weekly but daily forecasts are required, disaggregation means allocating the weekly total down to individual days using a learned intra-week pattern (proportional allocation) or auxiliary daily-level covariates, propagating the resulting extra uncertainty honestly rather than presenting disaggregated numbers with false daily-level precision, and evaluating disaggregated accuracy indirectly since true daily ground truth doesn't exist by construction.
Structured elaboration
- Proportional allocation using intra-week patterns: estimate a typical day-of-week SHARE of weekly total from historical data where finer granularity WAS available (or from a comparable series that IS tracked daily), then apply those shares to disaggregate a purely-weekly total into daily estimates - simple and often reasonably accurate when the intra-week pattern is genuinely stable, but degrades if the true daily pattern shifts (a promotion concentrated on a specific day, say) in a way the historical average share doesn't capture.
- Using auxiliary covariates: if a genuinely daily-level auxiliary signal correlated with the target exists (daily website traffic as a proxy for daily sales, even though only weekly sales totals are directly available), use its daily SHAPE to inform the disaggregation rather than relying purely on a fixed historical day-of-week average - this captures day-specific deviations (an auxiliary spike on a particular Tuesday) that a fixed proportional-allocation scheme would miss entirely.
- Interpolation approaches: smoother interpolation methods (e.g. constrained to sum back to the correct weekly total) can be appropriate for a genuinely smoothly-varying underlying process, but are a poor fit if the true daily pattern has sharp features (weekday vs weekend structure) that pure smoothing would wash out - proportional allocation using a known daily-of-week PATTERN is usually more appropriate than generic interpolation for exactly this reason.
- Propagating uncertainty from aggregated to disaggregated forecasts: the disaggregated daily forecast is necessarily MORE uncertain than the weekly aggregate it was derived from (you're adding genuine additional uncertainty about the WITHIN-week split, on top of whatever uncertainty already existed in the weekly total itself) - this must be reflected explicitly in the daily forecast's own interval, not silently dropped by presenting a disaggregated point number with no wider uncertainty than the aggregate had.
- Evaluating disaggregated predictions without daily ground truth: since true daily actuals genuinely don't exist to check against directly, evaluate INDIRECTLY - check that disaggregated forecasts correctly SUM BACK to the known, verifiable weekly actuals (a basic sanity/coherence check); validate the assumed intra-week SHARE pattern itself against any comparable series or historical period where finer granularity WAS available; and, where possible, validate against a genuinely different, independently-measured daily-level proxy signal (even if imperfect) as an indirect accuracy check.
Worked example
A retailer needing daily forecasts from weekly sales totals for staffing purposes might disaggregate using a historically-stable weekday/weekend share pattern (e.g. Saturday consistently carrying ~22% of weekly sales) - reasonably reliable for typical weeks, but this fixed-share approach would systematically mis-allocate a week containing an unusual one-off event (a Tuesday flash sale) concentrated on a day the historical average share doesn't anticipate, which is exactly where incorporating an auxiliary daily signal (if available) would meaningfully improve on pure proportional allocation.
Trade-offs & pitfalls
The most consequential mistake is presenting disaggregated daily numbers with the SAME apparent confidence/precision as the weekly aggregate they were derived from - a daily figure derived by splitting a weekly total is inherently a weaker, more uncertain estimate than the weekly number itself, and failing to communicate that (via a visibly wider interval, or explicit caveats) misleads a downstream consumer (like a staffing planner) into over-trusting a day-level precision the underlying data genuinely can't support.
Describe additive vs multiplicative seasonality in time series and explain why choosing the right decomposition model matters when establishing baselines or detecting anomalies. Give examples of metrics where each type is more appropriate and how you would test which model fits better.
Sample Answer
Direct answer
Additive seasonality assumes the seasonal swing is a roughly constant absolute amount regardless of the series' level; multiplicative seasonality assumes it scales proportionally with the level. Choosing the wrong one distorts both baselines (an additive model under-predicts the seasonal swing at a high level, or over-predicts at a low one) and anomaly thresholds (a fixed-width band around an additive baseline will be too tight during high-level periods and too loose during low-level ones).
Structured elaboration
- Additive: yt=trendt+seasonalt+residualt - the seasonal swing stays roughly the same size in absolute units no matter what the trend level is doing.
- Multiplicative: yt=trendt×seasonalt×residualt - the seasonal swing grows or shrinks proportionally with the trend level; a multiplicative model can be fit as an additive one on the LOG of the series, since log(yt)=log(trendt)+log(seasonalt)+log(residualt).
- Which metrics favor which: revenue-style metrics that grow substantially over time, where the seasonal spike naturally grows alongside the business (e.g. a December bump that's proportionally consistent but has grown from $10K to $50K as the business scaled), are usually multiplicative. Metrics with a roughly stable base level and a genuinely fixed-size seasonal effect (e.g. a fixed number of extra support tickets every Monday, regardless of overall ticket volume trend) are more often additive.
- Testing which model fits better: the simplest visual test is whether the peak-to-trough seasonal amplitude visibly GROWS alongside the trend on a raw plot - if it does, additive is the wrong assumption. More formally, fit both, compare residual variance (an additive fit on a genuinely multiplicative series will show residual variance that itself grows with the level, a clear diagnostic on a residual-vs-fitted plot), or simply compare backtested forecast error between the two.
- Why the choice matters for baselines/anomaly detection: an anomaly-detection threshold built on additive-model residuals (e.g. "flag anything more than 3 residual-standard-deviations away") implicitly assumes constant residual variance across the whole series; if the true process is multiplicative, that fixed threshold will be too sensitive (false positives) during low-level periods and too insensitive (missed real anomalies) during high-level periods.
Worked example
Two metrics side by side: daily active users growing from 10,000 to 100,000 over two years, with a weekend dip that's always been roughly 15% below the weekday average - that's multiplicative (the absolute size of the dip has grown 10x alongside the user base, but the RATIO has stayed constant). A metric like "number of scheduled maintenance windows per week," with a fixed operational cadence unrelated to overall traffic growth, is more likely additive.
Trade-offs & pitfalls
Log-transforming to convert a multiplicative problem into an additive one is convenient (lets you reuse additive-model tooling) but changes how you have to interpret and back-transform prediction intervals - a symmetric interval in log-space becomes an ASYMMETRIC interval once exponentiated back to the original scale, which is correct behavior (uncertainty genuinely should be asymmetric on a multiplicative series) but is easy to get wrong if you forget to back-transform properly.
Explain the difference between forecasting and causal inference in a business context. Give examples of when each approach is appropriate (for example, demand planning versus measuring marketing lift), describe core assumptions required for causal claims, and explain how a BI analyst should decide which approach to use when stakeholders ask for 'what will happen' versus 'what caused it'.
Sample Answer
Direct answer
Forecasting predicts WHAT WILL HAPPEN by extrapolating patterns, while causal inference asks WHAT CAUSED an observed change and requires a different set of assumptions (a valid comparison group, or an experiment) to answer credibly; demand planning is a forecasting problem, while measuring the lift from a marketing campaign is a causal-inference problem, and conflating the two - using a forecasting model's output as if it answered a causal question - is a common and consequential mistake.
Structured elaboration
- Forecasting: uses historical patterns (trend, seasonality, correlated signals) to project forward, with NO requirement that the model understand mechanism or causation - a model that has never heard of "why" can still forecast well if the pattern is stable. Appropriate when the question is purely "what's likely to happen if nothing unusual intervenes."
- Causal inference: asks what would have happened in a counterfactual world WITHOUT a specific intervention, which forecasting alone cannot answer, because a plain extrapolation of history has no way to represent "the same period, but without the campaign." Appropriate when the question is "did X cause Y," and answering it credibly requires either a genuine randomized experiment, or a quasi-experimental design (difference-in-differences, synthetic control, regression discontinuity) with its own specific, checkable assumptions.
- Core assumptions required for causal claims: at minimum, some form of comparability between what happened and what would have happened otherwise - either through randomization (an A/B test, the gold standard) or through an argued similarity between a treated group and a comparison group that wasn't exposed to the intervention (with assumptions like "parallel trends" for difference-in-differences, or "no other simultaneous change" for a simple before/after comparison), each of which can fail in ways that are not always obvious from the data alone.
- Deciding which approach to use: when a stakeholder asks "what will next quarter look like" - forecasting. When a stakeholder asks "did our marketing campaign work" or "would revenue have grown anyway" - causal inference, and a pure forecast (even an accurate one) does not answer that question, because an accurate forecast of the ACTUAL future doesn't tell you what the counterfactual (no-campaign) future would have looked like.
Worked example
A revenue series shows +15% growth the same quarter a new marketing campaign launched. A forecasting model extrapolating the pre-campaign trend might have predicted +8% growth anyway from ordinary momentum and seasonality - the DIFFERENCE between the forecast's counterfactual-like extrapolation and the observed +15% (roughly +7 percentage points) is a rough causal-impact ESTIMATE, but only a credible one if the forecasting model's pre-period fit was genuinely reliable and nothing else changed at the same time; a rigorous causal-impact method (like BSTS-based causal impact analysis, or a proper control-group comparison) formalizes exactly this idea with an explicit counterfactual and uncertainty interval, rather than treating a forecast's extrapolation as automatically causal.
Trade-offs & pitfalls
The most consequential version of this mistake is presenting a forecast-vs-actual gap as if it were automatically a measured causal effect, without checking whether anything ELSE changed at the same time that could explain the gap - seasonality not fully captured by the forecasting model, a competitor's simultaneous move, or a broader macro shift are all alternative explanations a rigorous causal analysis has to rule out (or explicitly account for) that a bare forecast comparison does not.
Unlock Full Question Bank
Get access to all 37 Forecasting and Time-Series Analysis interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.