Reshaping Data: Join, Stack, Aggregate, Dedup & Sample

Real data lives in more than one table and rarely in the shape your analysis needs. Stratum brings the full reshaping toolkit in-app — and every operation is non-destructive, so your originals are never at risk.

Until now we've worked with a single, tidy table. Reality is messier. Your sales sit in one file, one row per order. The details about each store — its region, type, and size — sit in another. To answer a question as basic as "which region earns the most revenue?", you first have to bring those tables together, then summarize them to the right level of detail. This is data reshaping, and it's where a lot of analysis quietly happens.

We'll switch datasets for this lesson, because reshaping only makes sense with relational structure: a fact table of retail orders and a dimension table of stores, linked by a shared StoreID.

Two related datasets open: retail sales and stores
Two related tables: ~18,800 order lines and 20 stores, sharing StoreID.

Joining two tables

A join matches rows from two tables on a shared key. Here, joining the sales table to the stores table on StoreID stitches each store's attributes onto every order line — so each sale now knows its region, store type, and city.

Configuring a left join on StoreID
Joining sales to stores on StoreID with a left join.

The join type matters. An inner join keeps only rows that match in both tables. A left join keeps every row from your primary (left) table, filling in blanks where the other table has no match. For analysis you usually want a left join from the fact table — that way you never silently drop a sale just because its store record happens to be missing.

The joined dataset with region and store columns added
After the join, every order line carries its store's attributes.

Adding group-level statistics

Now you can answer the revenue question. Aggregate Data computes a statistic for each group and writes it back as a new column. Pick one or more value columns (the parameters), choose the columns to group by — here Region and ProductCategory — and pick a statistic, say the sum. Stratum adds a column holding each group's total Revenue; you can repeat that value on every row in the group, or place it on just the first row of each group.

Aggregating summed revenue by region and product category
Aggregate Data adds a group statistic — here, summed revenue by region and category — as a new column.

It's one statistic per run: to also see the average Discount or a row count per group, run Aggregate again with that statistic selected. Choosing the group keys and the statistic is the analysis — summing Revenue measures the business outcome, averaging Discount describes pricing behavior, and a count tells you how much each figure rests on.

Want several statistics side by side in one place? That's what the Summary report is for — it breaks one or more measures down by your grouping columns (sums, means, counts and more) as a single pivot you can read or export.

Tidy data, briefly. Most statistical and charting routines expect "tidy" data — one observation per row. When measurements are spread across several columns, Stratum's Stack operation reshapes them from wide to tall, the bridge between a spreadsheet export and an analysis-ready table.

Cleaning up: dedup and sample

Two more operations round out the toolkit. Deduplication guards against double-counting: define the columns that make a row unique — here, OrderID — and keep the first or last occurrence. Run on a clean order table, it doubles as an integrity check (you'd expect zero duplicates).

Deduplicating on OrderID
Dedup on OrderID — also a quick data-integrity check.

Sampling draws a random subset. A 10% sample makes iteration fast while you're exploring, and because the rows are chosen at random — not just the first N — the subset stays representative of the whole.

Drawing a 10% random sample into a new dataset
A 10% random sample, created as its own dataset.
Nothing is silently lost. Join, Stack, and Sample each produce a new dataset, leaving your sources untouched. Aggregate adds columns to the current table and Deduplicate removes rows from it — but each is a single, fully undoable step (⌘Z), so you can always step back and experiment freely.

Follow along

Datasets
retail_sales.csv · stores.csv
You'll use
Join, Aggregate, Stack, Deduplicate and Sample
Up next
Histograms & Distribution Shape

With data imported, derived, filtered, and reshaped, the groundwork is done. From the next lesson on, we turn to seeing and testing — starting with the chart that begins almost every analysis: the histogram.