Day 1 Β· Concepts Β· ~45 min
π Theory
Almost every analytical question has the same shape: "What is the amount of X, for this category, in that period?" That shape is a data cube:
- Measures β the numbers you add up (an amount, a count, a weight).
- Dimensions β the coordinates that say what a number means: which Position, which Year, which Currency.
- Facts β one measurement at one set of coordinates. "Cash, 2024, CHF β 50".
A balance sheet looks like a table with rows and a couple of year columns. But that table is just one view of an underlying cube. Once you store the facts as a cube β Position Γ Year Γ Currency β Amount β you can re-pivot it into any table, chart, or KPI you like, without re-entering a single number.
The MeshWeaver twist: everything in the cube is a mesh node. The dimension types are nodes, the dimension members are nodes, the facts are nodes, and β you'll see in Lesson 6 β even the formulas are data on nodes. No database, no foreign keys, no surrogate ids. A node's identity is its path.
β‘ Experience it
Here is the smallest useful cube: six asset facts, each at coordinates (Position, Year), pivoted into rows Γ columns with totals. Run it, then read it bottom-up: the flat list of facts becomes a table purely by grouping on dimensions.
Define a Fact record (Position, Year, Amount) and load twelve asset facts β six positions across 2024 and 2025. Pivot them with ToPivotGrid: positions on rows, years on columns, summing Amount, with row and column totals.
Notice you never told it what the table should look like β only which dimension goes on rows and which on columns. That separation is the whole game. Swap GroupRowsBy and GroupColumnsBy and the same facts become a different table.
βοΈ Your turn
Difficulty: π’ Easy β 10β15 minutes
A coffee shop logs each day's sales as Sale(Product, Day, Cups). Complete the pivot so it shows Products down the rows, Days across the columns, summing cups, with row and column totals.
using MeshWeaver.Layout.Pivot;
record Sale(string Product, string Day, double Cups);
Sale[] sales =
[
new("Espresso", "Mon", 30), new("Latte", "Mon", 22), new("Espresso", "Tue", 28),
new("Latte", "Tue", 19), new("Espresso", "Wed", 35), new("Latte", "Wed", 26),
];
sales.ToPivotGrid(pivot => pivot
// π YOUR TURN: rows by Product, columns by Day, sum the Cups, add both totals.
.GroupRowsBy(/* ? */)
.GroupColumnsBy(/* ? */)
.Aggregate(/* ? */, agg => agg.WithFunction(AggregateFunction.Sum))
.WithRowTotals()
.WithColumnTotals())
Target: Espresso row total = 93, Latte row total = 67, Wed column total = 61.
Run it in your scratchpad or hand it to the Coach. Stuck? Now make it yours β three graded exercises Β» (π’ warm-up Β· π‘ the real thing Β· π΄ the stretch, each with a worked solution).
Check yourself
Quick questions on this lesson β instant feedback and a score.
Next: Lesson 2 β Decompose the statement into positions Β»