← All examples
21

Canonical Grid model

Live Revenue KPI

Keep paid-order revenue and margin enriched by customer and product dimensions, KPI cells, and a dashboard current as source rows change.

Scale
Medium
Source
21-live-revenue-kpi.grid
Length
93 lines
Collection
Live data & operations
Level
Intermediate
Runtime
Model tables + surface
Version
1.0.0

Watch it in Grid

See this model in motion.

Watch the model respond in the product, then inspect the exact source and checkpoints on this page.

Companion film

Many hands

Watch an offscreen teammate change units and leave a comment while the shared model updates without a refresh.

24 secGrid 0.61.0
Open film page

What this model gives you

A live relational pipeline whose filters, joins, KPIs, and dashboard tiles settle together after source changes.

30 min to study · Source reviewed 2026-08-24

Continue with guided practice

What to notice

  • Durable source tables
  • Keyed enrichment
  • Grouped KPIs
  • Layout bindings

Requirements

  • Model tables
  • Layout surface
  • Source rows must be supplied

Expected checkpoint

A known state for this walkthrough.

After loading the tutorial sample rows into the three named schemas.

Revenue
90,000With tutorial sample rows
Margin
63,000With tutorial sample rows
Segments
2With tutorial sample rows
Alert
FALSEWith tutorial sample rows
01 · Admit

Sources stay ordinary model tables

Connectors, imports, table edits, or mutations can feed the same Orders, Customers, and Products contracts.

02 · Enrich

Two joins preserve a legible calculation path

Paid orders gain segment, cost, and category before margin is grouped by segment.

03 · Present

The dashboard follows semantic KPI cells

Layout tiles bind to TotalRevenue, TotalMargin, RevenueAlert, and ActiveSegments instead of duplicating formulas.

21-live-revenue-kpi.grid
Get Grid
MODEL "Live Revenue KPI"
DESCRIPTION "Keep paid-order revenue and margin enriched by customer and product dimensions, KPI cells, and a dashboard current as source rows change."
VERSION "1.0.0"
AUTHOR "Grid"
TAGS "live-model", "relational", "join", "kpi", "dashboard", "surfaces"

# Orders and Customers are durable model tables populated by connectors,
# imports, rules, or ordinary table mutations. Every derived table below stays
# current incrementally, and the KPI cells and dashboard follow their revisions.
table Orders = { schema: "Orders" }
table Customers = { schema: "Customers" }
table Products = { schema: "Products" }

table PaidOrders = SELECT customer_id, product_id, amount AS revenue
  FROM Orders
  WHERE status = "paid"

table CustomerEnrichedOrders = SELECT p.customer_id, p.product_id, p.revenue, c.segment
  FROM PaidOrders AS p
  LEFT JOIN Customers AS c ON p.customer_id = c.customer_id

table EnrichedPaidOrders = SELECT e.customer_id, e.revenue,
    e.revenue * (1 - COALESCE(p.cost_rate, 0)) AS margin,
    e.segment, p.category
  FROM CustomerEnrichedOrders AS e
  LEFT JOIN Products AS p ON e.product_id = p.product_id
  WHERE e.revenue > 0
    AND (p.category IN ("software", "services") OR p.category IS NULL)

table RevenueBySegment = SELECT segment, SUM(revenue) AS revenue,
    SUM(margin) AS margin
  FROM EnrichedPaidOrders
  GROUP BY segment

TotalRevenue IS currency = RevenueBySegment.sum("revenue")
TotalMargin IS currency = RevenueBySegment.sum("margin")
ActiveSegments = RevenueBySegment.count()
RevenueAlert = TotalRevenue > 100000

Dashboard!type = "layout"
Dashboard!config = """
version = 1
kind = "layout"
title = "Live Revenue"

[layout]
cols = 12
rows = 4
show_controls = true

[[tiles.static]]
title = "Paid Revenue"
x = 0
y = 0
w = 4
h = 2
formula = "=TotalRevenue"

[[tiles.static]]
title = "Paid Margin"
x = 4
y = 0
w = 4
h = 2
formula = "=TotalMargin"

[[tiles.static]]
title = "Revenue Alert"
x = 8
y = 0
w = 4
h = 2
formula = "=RevenueAlert"

[[tiles.static]]
title = "Freshness"
x = 0
y = 2
w = 8
h = 2
body = "Orders, Customers, and Products changes flow through filtering, keyed enrichment, post-join margin, and RevenueBySegment into these tiles without rebuilding the model."

[[tiles.static]]
title = "Active Segments"
x = 8
y = 2
w = 4
h = 2
formula = "=ActiveSegments"
"""
Dashboard!data = ""

END MODEL