← All examples
02

Canonical Grid model

Array Analytics

Portable analytics model built from spills, higher-order functions, and scenarios.

Scale
Medium
Source
02-array-analytics.grid
Length
31 lines
Collection
Start here
Level
Beginner
Runtime
Portable
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

One series, three futures

Change one month of units and watch mapped revenue, cumulative totals, and three scenario futures recalculate together.

49 secGrid 0.63.2
Open film page

What this model gives you

A five-month revenue series with cumulative totals and bear/base/bull scenario rows.

15 min to study · Source reviewed 2026-08-25

Continue with guided practice

What to notice

  • Array-valued cells
  • MAP, SCAN, and REDUCE
  • Two-dimensional comprehensions
  • BYROW and BYCOL summaries

Requirements

  • Portable
  • No connector
  • No network

Expected checkpoint

A known state for this walkthrough.

After loading the canonical source with its authored units, prices, and scenario multipliers.

Monthly revenue
[5,040, 5,940, 6,674, 7,350, 8,736]A3
Cumulative total
33,740A4 final / A5 / A8
Scenario totals
31,040.8 / 33,740 / 36,439.2M5 bear / base / bull
Scenario
bull-ledA9
01 · Vectorize

One formula prices every month

MAP pairs units and prices while SCAN and REDUCE expose both the running path and final total.

02 · Fan out

A comprehension creates the scenario matrix

Three multipliers cross five months without copying fifteen formulas.

03 · Summarize

Rows and columns answer different questions

BYROW totals each scenario; BYCOL confirms the symmetric scenario average returns the base month values.

02-array-analytics.grid
Get Grid
MODEL "Array Analytics"
DESCRIPTION "Portable analytics model built from spills, higher-order functions, and scenarios."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "portable", "arrays", "analytics"

# Base series: units and realized price by month
A1 = [120, 135, 142, 150, 168]
A2 = [42, 44, 47, 49, 52]

# Monthly revenue and cumulative revenue
A3 = MAP(A1, A2, (units, price) => ROUND(units * price, 2))
A4 = SCAN(0, A3, (acc, value) => ROUND(acc + value, 2))
A5 = REDUCE(0, A3, (acc, value) => ROUND(acc + value, 2))
A6 = ROUND(A5 / 5, 2)

# Scenario multipliers: bear, base, bull
G1 = [0.92; 1.00; 1.08]

# 3x5 scenario matrix (scenarios x months) built with a comprehension;
# lowers to a single MAKEARRAY cell under the hood.
G5 = [INDEX(A3, 1, month) * INDEX(G1, scenario, 1) FOR scenario IN 1..3, month IN 1..5]
M5 = BYROW(G5, row => SUM(row))
G9 = BYCOL(G5, col => AVERAGE(col))

# Compact outputs
A8 = SUM(A3)
A9 = INDEX(M5, 3) > INDEX(M5, 2) THEN "bull-led" ELSE "base-led"
A10 = `total={A8} avg={A6} scenario={A9}`

END MODEL