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:

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.

flowchart LR F["Fact<br/>(Position, Year) β†’ Amount"] -->|grouped by<br/>dimensions| P[Pivot table] F -->|sliced by<br/>dimensions| C[Chart] F -->|composed by<br/>formulas| K[KPIs]

⚑ 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 Β»

Reconnecting…
The connection to the server was interrupted. Trying to restore it…
Trying again…
The connection could not be restored. Reloading the page…
The server was updated. Reloading the page to pick up the latest version.