Fourth model
Weekly budget vs actual
Budgeted sales and labour against actuals, per budget week, location and department.
- Grain
- budget week x location x department
- Built from
- 4Raw tables
- 4Staging
- 3Core
- 1Analytics
- Reads from Fourth
- budgetpayrollsalesshift
- Ships as
- Weld and dbt SQL, open source on GitHub
core.fourth.weekly_budget_vs_actual
1-- core.fourth.weekly_budget_vs_actual
2-- Budgeted sales and labour against actuals, per budget week, location and
3-- department.
4-- Grain: budget week x location x department.
5--
6-- Weeks are Fourth's budget weeks (week_start to week_end inclusive). Actuals
7-- come from core.fourth.labour_vs_sales, summed over the days in the week, so the
8-- same caveats about payroll lines apply.
9
10WITH actuals AS (
11 SELECT
12 b.location_id,
13 b.department_id,
14 b.week_start,
15 SUM(a.actual_sales) AS actual_sales,
16 SUM(a.labour_cost) AS actual_labour_cost,
17 SUM(a.labour_hours) AS actual_labour_hours
18 FROM {{staging.fourth.budget}} b
19 JOIN {{core.fourth.labour_vs_sales}} a
20 ON a.department_id = b.department_id
21 AND a.date BETWEEN b.week_start AND b.week_end
22 GROUP BY 1, 2, 3
23)
24
25SELECT
26 b.week_start,
27 b.week_end,
28 b.location_id,
29 b.location_name,
30 b.department_id,
31 b.department_name,
32 b.sales_budget,
33 ROUND(COALESCE(a.actual_sales, 0), 2) AS actual_sales,
34 ROUND(COALESCE(a.actual_sales, 0) - b.sales_budget, 2) AS sales_vs_budget,
35 b.labour_budget_pct,
36 ROUND(b.labour_budget_amount, 2) AS labour_budget_amount,
37 ROUND(COALESCE(a.actual_labour_cost, 0), 2) AS actual_labour_cost,
38 ROUND(COALESCE(a.actual_labour_cost, 0) - b.labour_budget_amount, 2) AS labour_vs_budget,
39 SAFE_DIVIDE(a.actual_labour_cost, a.actual_sales) AS actual_labour_pct_of_sales,
40 ROUND(COALESCE(a.actual_labour_hours, 0), 2) AS actual_labour_hours,This model and the 7 it depends on. Deploy them together; refs like {{staging.…}} resolve to the matching folders in Weld, and the dbt view uses source() and ref().
Notes
How it counts. And where it stops.
Weeks are Fourth's budget weeks (week_start to week_end inclusive). Actuals come from core.fourth.labour_vs_sales, summed over the days in the week, so the same caveats about payroll lines apply.
Raw tables it reads
- raw.fourth.budget
- raw.fourth.payroll
- raw.fourth.sales
- raw.fourth.shift
More Fourth models
Put Fourth in front
of your agents.
Connect Fourth, deploy the models, and ask questions in Claude, Cursor or ChatGPT. Free for 14 days, no credit card.