Tabellab

Row Labels: What a PivotTable Does, Rebuilt with UNIQUE and SORT

Lesson 1 of 20Lab

All lessons
  1. Row Labels: What a PivotTable Does, Rebuilt with UNIQUE and SORTLabFree
  2. Values: SUMIFS over the Spilled Labels (H2#)Lab Locked
  3. Cross-Tabs: Rows × Columns with UNIQUE, TRANSPOSE and One SUMIFS GridLab Locked
  4. Show Values As: % of Grand Total, % of Row and % of ColumnLab Locked
  5. Count, Average, Max and Distinct Count: COUNTIFS, AVERAGEIFS, MAXIFSLab Locked
  6. Report Filters: Criteria Cells, (All) and a Drill-Down ListLab Locked
  7. Grouping Dates by Month and Quarter: EOMONTH and Text KeysLab Locked
  8. Mid-course project: A Subtotal Report, a Summary that Ignores It, and a ChartLab Locked
  9. Show Values As Difference From: Month-on-Month Change and a Base RegionLab Locked
  10. Running Total In and % Running Total: Cumulative Months by CategoryLab Locked
  11. % of Parent Row Total: Shares Inside a Two-Level Region / Category ReportLab Locked
  12. Show Values As Index: Which Region Over- or Under-Sells a Category?Lab Locked
  13. Calculated Fields Done Right: Margin % as a Ratio of Sums, Not an Average of RatiosLab Locked
  14. Empty Items, (blank) Labels and Zeros: A Report That Shows Every RowLab Locked
  15. Custom Groups with a Mapping Table: Products into Departments and the Unmapped CheckLab Locked
  16. Grouping Numbers: Order-Size Bands Like "Starting at 0, By 500"Lab Locked
  17. Grouping by Week and by Weekday: Monday Week Keys and a Weekday ProfileLab Locked
  18. GROUPBY and PIVOTBY: The Whole Report in One Formula, Checked Against SUMIFSLab Locked
  19. Working from a Pasted PivotTable: Fill Down Row Labels and Unpivot a Cross-TabLab Locked
  20. Final Project: A Filtered H1 Summary Dashboard with KPIs, a Category Report and a Trend ChartLab Locked

You are not signed in — the lab works, but your progress is not saved. Sign up

Lesson 1 of 20 is free. Unlock all 20 hands-on labs, the final exam and your certificate.

Buy course — $9.90
Read first

The same thing with a real PivotTable

  • Click any cell inside the data and choose Insert > PivotTable (tip: first press Ctrl+T to turn the data into a Table, so new rows are picked up on refresh).
  • In the PivotTable Fields pane, drag Category into Rows. Excel lists each category once and sorts it A→Z.
  • Drag Region above Category in Rows to get a two-level outline. Report Layout > Show in Tabular Form puts the two fields side by side, like our two-column UNIQUE.
  • The browser grid in these labs has no PivotTable button. Everything a PivotTable shows can also be built with formulas, and that is what you practise here.
Loading the spreadsheet…

The monthly report problem

Every month, someone in almost every company gets the same request: show me revenue by category, by region, by month. The data is a long list of order lines, and the answer is a small summary table. Most people build it with a PivotTable, and that works well until the layout needs to match a template, a number has to be checked cell by cell, or someone forgets to press Refresh before the report goes out. This course is for analysts, controllers, sales operations and small-business owners who want summary reports that update themselves, sit exactly where they are needed and can be audited by anyone who clicks a cell.

The idea is simple: everything a PivotTable shows can be rebuilt with a handful of modern Excel formulas. In this first lesson you rebuild the part that everything else depends on, the row labels. That is the list of distinct categories (or regions, or products) down the left side of every summary. Get that list right with one live formula, and every number next to it can follow automatically.

We use the data of Brightwater Outdoor Co., a fictional outdoor-gear wholesaler with 20 order lines for the first quarter of 2026. The same data sits in the lab above, so you can try each formula as you read.

What a PivotTable really does

A PivotTable has four areas in its Fields pane. Rows gives you one line per distinct value of a field. Columns gives you one column per distinct value. Values fills the grid with a Sum, Count, Average or another summary. Filters limits the whole report to a subset, such as one sales channel. Strip away the drag-and-drop interface and each area is a small, well-defined calculation. That is why each one has a formula twin.

The four PivotTable areas and their formula twinsFiltersA criteria cell, e.g. Channel = OnlineSUMIFS(…, D2:D21, filter cell)ColumnsOne column per distinct valueTRANSPOSE(SORT(UNIQUE(B2:B21)))Rows (this lesson)One line per distinct valueSORT(UNIQUE(C2:C21))ValuesSum, Count, Average … per labelSUMIFS(F2:F21, C2:C21, H2#)Lessons 1 and 7Lessons 3 and 4Lesson 6Lessons 2, 4 and 5
Each PivotTable area has a formula equivalent. This lesson builds the Rows area; the rest of the course adds the other three.

The Rows area is the foundation. Before Excel can sum revenue per category, it has to know which categories exist. A PivotTable finds them by scanning the field and listing each value once, sorted A→Z by default. In formula terms that is two functions: UNIQUE to remove duplicates and SORT to put the result in order.

UNIQUE and SORT, explained simply

=UNIQUE(C2:C21) looks at the 20 category cells and returns every value once, in the order in which it first appears. For Brightwater that is Tents (row 2), Footwear (row 3), Packs (row 4) and Apparel (row 5). The result is a dynamic array: you type the formula in one cell and Excel spills the four results into the cells below. If you add an order line with a new category to the source range, the list grows by itself.

=SORT(UNIQUE(C2:C21)) wraps the distinct list in SORT, which sorts it ascending by default. Now the list reads Apparel, Footwear, Packs, Tents, exactly like a PivotTable's default row order. SORT has optional arguments: the column to sort by, the order (1 for ascending, -1 for descending) and whether to sort by columns instead of rows. For a single column of labels the defaults are all you need.

From 20 order lines to 4 sorted row labelsC2:C21 (20 lines)TentsFootwearPacksApparelTentsPacksApparelFootwearPacksTentsApparelFootwearFootwearApparelTentsPacksTentsFootwearTentsPacksUNIQUEfirst appearanceTentsFootwearPacksApparelSORTA→Z (H2:H5)ApparelFootwearPacksTents=SORT(UNIQUE(C2:C21)) spills 4 rows
UNIQUE removes the duplicates and keeps the order of first appearance. SORT then puts the four labels in A→Z order, ready to be the row labels of a report.

UNIQUE, SORT and the spill behaviour are dynamic array features. They are available in Excel for Microsoft 365, Excel 2021 and later, Excel for the web and current Excel for Mac. In Excel 2019 and older these formulas show #NAME?.

Worked example: Brightwater Outdoor Co., Q1 2026

Here is the full source data from the lab, A1:F21. Each line is one order with its region, product category, sales channel, units and revenue. All names and numbers are fictional.

OrderRegionCategoryChannelUnitsRevenue
BW-1001NorthTentsOnline41,560
BW-1002WestFootwearRetail121,380
BW-1003SouthPacksOnline91,035
BW-1004NorthApparelRetail201,100
BW-1005EastTentsRetail31,290
BW-1006WestPacksOnline7840
BW-1007EastApparelOnline15795
BW-1008SouthFootwearRetail101,240
BW-1009NorthPacksRetail6702
BW-1010WestTentsOnline52,050
BW-1011SouthApparelOnline18936
BW-1012EastFootwearOnline81,032
BW-1013NorthFootwearOnline111,353
BW-1014WestApparelRetail221,166
BW-1015SouthTentsRetail2860
BW-1016EastPacksRetail101,150
BW-1017NorthTentsRetail31,200
BW-1018WestFootwearOnline91,107
BW-1019EastTentsOnline41,680
BW-1020SouthPacksRetail8960

Step 1, the row labels. In H2 type =SORT(UNIQUE(C2:C21)). The formula spills into H2:H5 and returns Apparel, Footwear, Packs and Tents. H5, the last label, is Tents. That is the cell the Coach checks in the lab.

Step 2, the distinct count. A report often needs to know how many rows it will have, for example to size a chart or to check that no category is missing. In L2 type =ROWS(UNIQUE(C2:C21)), or refer to the spilled list directly with =ROWS(H2#). Both return 4. The # after H2 is the spill range operator: it always means "the whole result that spills from H2", however long it currently is. =ROWS(C2:C21) would return 20, the number of order lines, which is a common mix-up.

Step 3, two fields in Rows. When you drag Region and then Category into a PivotTable's Rows area, you get a two-level outline: each region, and under it the categories that occur in that region. The formula version is a two-column UNIQUE: =UNIQUE(B2:C21) returns every Region/Category combination that occurs in the data. To sort it by region first and then by category within each region, give SORT an array of sort columns: =SORT(UNIQUE(B2:C21),{1,2}). Brightwater sells all four categories in all four regions, so the list has 16 rows:

Region (J)Categories (K), sorted A→Z within the regionRows
EastApparel, Footwear, Packs, Tents4
NorthApparel, Footwear, Packs, Tents4
SouthApparel, Footwear, Packs, Tents4
WestApparel, Footwear, Packs, Tents4

East comes first alphabetically and fills J2:K5. North starts in row 6, so K6 is Apparel, the first category of North. If you sort only by the first column with =SORT(UNIQUE(B2:C21)), the regions are in order but the categories inside each region keep their order of first appearance. In this data North would then start with Tents, not Apparel. That is exactly the subtle difference a PivotTable hides from you, and a formula makes visible.

Where this leads. Once the labels exist, the values are one formula away. The table below is a preview of the next lesson: the row labels from H2#, an order count with COUNTIFS and the revenue with SUMIFS, both pointing at the spilled list so they grow and shrink with it.

H (row labels)Order lines
=COUNTIFS(C2:C21,H2#)
Revenue
=SUMIFS(F2:F21,C2:C21,H2#)
Share
Apparel43,99717.1%
Footwear56,11226.1%
Packs54,68720.0%
Tents68,64036.9%
Grand total2023,436100.0%

What the row labels feed: Q1 revenue by category02,5005,0007,50010,000Apparel3,997 (4 lines, 17.1%)Footwear6,112 (5 lines, 26.1%)Packs4,687 (5 lines, 20.0%)Tents8,640 (6 lines, 36.9%)Labels from =SORT(UNIQUE(C2:C21)), values from =SUMIFS(F2:F21,C2:C21,H2#)
Brightwater Q1 2026 revenue by category, built from the row labels in H2# and one SUMIFS. Tents lead with 8,640 of 23,436.

How to build the row labels in Excel, step by step

  1. Click any cell in the data and press Ctrl+T (Insert > Table) if you want new order lines to be included automatically. Confirm that the table has headers.
  2. Leave at least one empty column between the data and your report, so the spilled results never collide with the source data. In the lab the report starts in column H.
  3. Click H1, type the header Category, then click H2 and type =SORT(UNIQUE(C2:C21)). If you converted the data to a Table, Excel may write =SORT(UNIQUE(Table1[Category])) when you select the column; both work.
  4. Press Enter. The list spills into H2:H5. A thin blue border appears around the spill range when you select any cell in it.
  5. Make sure the cells below H2 are empty. If anything is in the way, Excel shows #SPILL! in H2. Clear the blocking cell and the list appears.
  6. In L2 type =ROWS(H2#) to count the labels. Type the # yourself, or select the whole spill range with the mouse and Excel inserts it for you.
  7. For the two-level list, click J2 and type =SORT(UNIQUE(B2:C21),{1,2}). The curly brackets create an array constant: sort by column 1, then by column 2.
  8. Test it: change one category in the source, for example C21 from Packs to Stoves. A fifth label appears in H2:H6, L2 shows 5, and the two-level list gains a South/Stoves row. Press Ctrl+Z to undo.
To get the labels in descending order, use =SORT(UNIQUE(C2:C21),,-1). The empty second argument keeps the default sort column, and -1 reverses the order.

PivotTable or formulas: which should you use?

Both have their place. A PivotTable is unbeatable for quick exploration: drag a field, look, drag another. A formula report wins when the summary has a fixed layout, has to update without anyone remembering to refresh, or needs to be checked by an auditor or a manager who wants to see where a number comes from.

PivotTableFormula report
Updates when data changesOnly after Refresh (Alt+F5, or Ctrl+Alt+F5 for all)Instantly, like any formula
LayoutFixed grid, limited formatting optionsAny cell, any layout, mix with other formulas
Checking a numberDouble-click to drill downClick the cell and read the formula
Distinct countNeeds the Data Model=ROWS(UNIQUE(C2:C21))
Speed of buildingVery fast, drag and dropA few formulas, then reusable
Excel versionEvery desktop versionMicrosoft 365, Excel 2021 or later for UNIQUE/SORT

If you want to compare the two yourself in desktop Excel: click a cell in the data, choose Insert > PivotTable, place it on a new sheet, and drag Category into Rows. Then drag Region above Category, and under Design > Report Layout choose Show in Tabular Form to see the two fields side by side, just like J:K. Newer Microsoft 365 versions also include the functions GROUPBY and PIVOTBY, which build a whole summary in one formula. They are useful to know about, but UNIQUE, SORT and SUMIFS work in more Excel versions and show every step clearly, which is why this course builds on them.

Pivot-style summary reports in Excel with UNIQUE, SORT, SUMIFS, cross-tabs and subtotals
Pivot-style summary reports with formulas: row labels, values, cross-tabs, filters, date grouping and subtotals.

Common mistakes and how to spot them

  • #SPILL! in the label cell. Something is in the cells the result wants to occupy, even a single space. Click the error, open the small warning menu and choose Select Obstructing Cells, then clear them.
  • Unsorted labels. =UNIQUE(C2:C21) alone keeps the order of first appearance. If your list starts with Tents instead of Apparel, wrap it in SORT.
  • Hidden duplicates. "Tents" and "Tents " (with a trailing space) are different values to UNIQUE, so you get two Tents rows. Look for labels that seem identical, and clean the source with TRIM, or use =SORT(UNIQUE(TRIM(C2:C21))).
  • A 0 at the end of the list. If your range includes empty cells, UNIQUE returns one blank value that displays as 0. Exclude blanks with =SORT(UNIQUE(FILTER(C2:C99,C2:C99<>""))).
  • Counting lines instead of labels. =ROWS(C2:C21) returns 20. A distinct count needs =ROWS(UNIQUE(C2:C21)) or =ROWS(H2#).
  • Sorting a two-column list by one column only. =SORT(UNIQUE(B2:C21)) sorts by region but leaves categories inside a region in their original order. Use {1,2} as the sort index.
  • Fixed ranges that stop too early. If new orders are added in row 22 and your formula says C2:C21, they are ignored. Use an Excel Table or a range with room to grow plus FILTER for blanks.
UNIQUE is not case-sensitive: "tents" and "Tents" count as the same value, and the result shows the spelling that appears first. That is usually what you want in a report, but it is worth knowing when you check totals.

Quick reference: functions and shortcuts used

Function / shortcutWhat it doesExample
UNIQUE(array, [by_col], [exactly_once])Returns each distinct value (or row) once, in order of first appearance.=UNIQUE(C2:C21)
SORT(array, [sort_index], [sort_order], [by_col])Sorts a range or array; sort_order 1 = ascending, -1 = descending.=SORT(UNIQUE(B2:C21),{1,2})
ROWS(array)Counts the rows of a range or array.=ROWS(UNIQUE(C2:C21))
COUNTA(value)Counts non-empty cells or array items.=COUNTA(UNIQUE(C2:C21))
H2#Spill range operator: refers to the whole spilled result of H2.=ROWS(H2#)
FILTER(array, include)Keeps only rows that meet a condition, e.g. no blanks.=UNIQUE(FILTER(C2:C99,C2:C99<>""))
Ctrl+TTurns a data range into an Excel Table that grows with new rows.Insert > Table
Alt+F5 / Ctrl+Alt+F5Refreshes the selected PivotTable / all data connections (Windows).PivotTable Analyze > Refresh

Real-world uses

  • Monthly management pack. A one-page summary of revenue by product line that sits in a fixed, branded layout and updates the moment the new month's data is pasted in, without anyone pressing Refresh.
  • Sales territory review. A two-level Region/Customer list built with SORT(UNIQUE(…),{1,2}) becomes the backbone of a territory report, showing every customer under its region with their sales next to it.
  • Data quality checks. A quick =SORT(UNIQUE(C:C)) on a supplier or cost-centre column exposes misspellings and stray spaces before they split one total into two.
  • Dropdown lists that maintain themselves. A spilled UNIQUE list can be the source of a Data Validation dropdown (source =$H$2#), so new categories appear in the dropdown automatically.
  • Dashboards and charts. Charts that point at spilled label and value ranges pick up new categories without editing the chart's data range by hand, as you will see in later lessons.

What you will build in the rest of this course

With the row labels in place, the remaining 19 labs rebuild every other part of a PivotTable with Brightwater's data, and each one is graded instantly so you know your formulas are right.

Values: SUMIFS over the Spilled Labels (H2#). You fill the Values column with one SUMIFS that follows the spilled labels, add a grand total, a calculated field (revenue per unit) and a version sorted largest first. This is the moment the report starts to look like a real PivotTable.

Cross-Tabs: Rows × Columns with UNIQUE, TRANSPOSE and One SUMIFS Grid. You build a revenue matrix with regions down and categories across, using a header formula, a single grid formula and row and column totals. One formula fills sixteen cells.

Show Values As: % of Grand Total, % of Row and % of Column. You turn the matrix into three percentage views and chart each region's category mix as a 100% stacked column chart, and learn which percentage answers which business question.

Count, Average, Max and Distinct Count: COUNTIFS, AVERAGEIFS, MAXIFS. You summarise orders per region four ways: number of orders, average order value, largest order and number of distinct customers, including the distinct count that a normal PivotTable cannot do without the Data Model.

Report Filters: Criteria Cells, (All) and a Drill-Down List. You add a Channel filter and a Region filter with an (All) option, then list the orders behind one number, just like double-clicking a value in a PivotTable.

Grouping Dates by Month and Quarter: EOMONTH and Text Keys. You roll half a year of order lines up to months and quarters with a helper key column and SUMIFS over the spilled keys, the formula version of a PivotTable's date grouping.

Mid-course project: A Subtotal Report, a Summary that Ignores It, and a Chart. You finish a printed subtotal report with SUBTOTAL, add a grand total that does not double count, rebuild the region summary with SUMIFS and chart it. You leave with a complete reporting pattern you can reuse on your own data.

Summary

A PivotTable's Rows area is just the distinct, sorted list of a field. =SORT(UNIQUE(C2:C21)) rebuilds it with one live formula, =ROWS(H2#) counts the labels, and =SORT(UNIQUE(B2:C21),{1,2}) creates a two-level Region/Category list sorted the way a PivotTable would sort it. Because the results spill and update instantly, every number you later attach to these labels stays in sync with the data.

Now try it in the lab above: build the sorted category list in H2, the distinct count in L2 and the two-level list in J2, then answer the PivotTable question in L4. It takes about fifteen minutes, and it is the foundation for every report in the rest of the course.

Frequently asked questions

How do I get a list of unique values in Excel without a PivotTable?

Use =UNIQUE(range), for example =UNIQUE(C2:C21). In Microsoft 365 and Excel 2021 or later the distinct values spill into the cells below automatically.

How do I sort a unique list alphabetically in Excel?

Wrap UNIQUE in SORT: =SORT(UNIQUE(C2:C21)). Add -1 as the third argument, =SORT(UNIQUE(C2:C21),,-1), for Z to A.

How do I count distinct values in Excel?

Count the rows of the unique list: =ROWS(UNIQUE(C2:C21)) or =COUNTA(UNIQUE(C2:C21)). If the list already spills from H2, =ROWS(H2#) gives the same result.

What does the # after a cell reference mean in Excel?

H2# is the spill range operator. It refers to the entire dynamic array that spills from H2, so formulas that use it grow and shrink with the list.

Why does my UNIQUE formula show #SPILL!?

One or more cells in the area where the results should spill are not empty. Select the error, choose Select Obstructing Cells from the warning menu and clear those cells.

Can formulas replace a PivotTable in Excel?

Yes. Row labels come from SORT(UNIQUE()), values from SUMIFS or COUNTIFS, column headers from TRANSPOSE(UNIQUE()) and filters from criteria cells. The formula report updates instantly and can be laid out freely.

Keep going: Pivot-Style Summary Reports with Formulas: UNIQUE, SUMIFS, Cross-Tabs & Subtotals

This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time $9.90.

  1. Values: SUMIFS over the Spilled Labels (H2#)
  2. Cross-Tabs: Rows × Columns with UNIQUE, TRANSPOSE and One SUMIFS Grid
  3. Show Values As: % of Grand Total, % of Row and % of Column
  4. Count, Average, Max and Distinct Count: COUNTIFS, AVERAGEIFS, MAXIFS
  5. Report Filters: Criteria Cells, (All) and a Drill-Down List
  6. Grouping Dates by Month and Quarter: EOMONTH and Text Keys
  7. Mid-course project: A Subtotal Report, a Summary that Ignores It, and a Chart
  8. Show Values As Difference From: Month-on-Month Change and a Base Region
  9. Running Total In and % Running Total: Cumulative Months by Category
  10. % of Parent Row Total: Shares Inside a Two-Level Region / Category Report
  11. Show Values As Index: Which Region Over- or Under-Sells a Category?
  12. Calculated Fields Done Right: Margin % as a Ratio of Sums, Not an Average of Ratios
  13. Empty Items, (blank) Labels and Zeros: A Report That Shows Every Row
  14. Custom Groups with a Mapping Table: Products into Departments and the Unmapped Check
  15. Grouping Numbers: Order-Size Bands Like "Starting at 0, By 500"
  16. Grouping by Week and by Weekday: Monday Week Keys and a Weekday Profile
  17. GROUPBY and PIVOTBY: The Whole Report in One Formula, Checked Against SUMIFS
  18. Working from a Pasted PivotTable: Fill Down Row Labels and Unpivot a Cross-Tab
  19. Final Project: A Filtered H1 Summary Dashboard with KPIs, a Category Report and a Trend Chart

Buy course — $9.90 See the full course