Find a course

Module 5: Text, Dates and Dynamic ArraysLesson 12 of 1213 min

Dynamic Arrays: FILTER, SORT, UNIQUE and LET

Write one formula that spills a whole result with FILTER, SORT, UNIQUE and SEQUENCE, fix #SPILL! errors and simplify long formulas with LET.

Step 1 of 11Learn

One formula, a whole list

A team lead wants a list of every customer who ordered this quarter, without duplicates, sorted A to Z, on a summary sheet that updates itself. The classic approach was copy, paste, Remove Duplicates, sort, and repeat every week. In Microsoft 365 and Excel 2021 or later, it's one formula:

=SORT(UNIQUE(Orders[Customer]))

Press Enter, and the list fills as many cells as it needs. Add an order from a new customer and the list grows by one row. This behavior is called spilling, and functions designed for it are called dynamic array functions.

The formula lives only in the top-left cell. The other cells show its results in lighter text in the formula bar, and a thin blue border marks the spill range while you select it. To refer to the entire spilled result elsewhere, put # after the anchor cell: if the list starts in E2, =COUNTA(E2#) counts the customers, however many there are.

Dynamic arrays changed how good spreadsheets are built. Instead of hundreds of copied formulas, each of which can be edited or broken individually, you get one formula per result that's easy to audit.

One formula in E2 spills into as many cells as it needsRowE2=SORT(UNIQUE(...)) → Ana3Ben (spilled)4Cho (spilled)5Dev (spilled)Refer to the whole result as E2#

Step 2 of 11Learn

When a spill is blocked: #SPILL!

A spilling formula needs empty cells to fill. If anything is in the way, even a single space character, the formula shows #SPILL! instead of a partial result. Click the error's warning icon and choose Select Obstructing Cells to find the culprit, then clear it.

Other causes:

  • Inside an Excel table. Tables don't allow spilling formulas in their columns. Put dynamic array formulas outside tables, or reference tables from a normal range.
  • Merged cells in the spill area.
  • Off the edge of the sheet. =A:A*2 entered in row 2 would need more rows than the worksheet has, so it returns #SPILL!. Reference the data you need, ideally a table column.

You can't type into the middle of a spill range, either. Editing a cell inside it blocks the spill. To change the results, change the formula or the source data.

Older Excel versions don't spill. If you open a dynamic array workbook in Excel 2016, formulas show as legacy array formulas with braces, and newer functions like FILTER show #NAME?. If a file must work on older versions, check before you rely on these functions.

Step 3 of 11Practice · True or false

You can overwrite one value in the middle of a spilled range to correct it, and the rest of the spill stays in place.

Step 4 of 11Learn

FILTER: rows that meet conditions

=FILTER(array, include, [if_empty]) returns only the rows of array where include is TRUE.

With an order table named Orders:

=FILTER(Orders, Orders[Region]="West", "No orders")

spills every West order, all columns, and updates as orders are added. If none match, you see "No orders" instead of the #CALC! error FILTER returns for an empty result.

Multiple conditions use arithmetic on TRUE/FALSE arrays:

  • AND: multiply the tests. (Orders[Region]="West")*(Orders[Amount]>500) is 1 only where both are TRUE.
  • OR: add them. (Orders[Region]="West")+(Orders[Region]="East") is at least 1 where either is TRUE.

So West orders over $500:

=FILTER(Orders, (Orders[Region]="West")*(Orders[Amount]>500), "None")

Each test must be wrapped in parentheses, because comparison operators come last in precedence. Orders[Region]="West"*Orders[Amount]>500 would multiply text by numbers and fail.

Point the conditions at input cells, such as a region in H1 and a minimum in H2, and you've built an interactive report: change H1 and the result changes.

Multiplying tests gives AND, adding gives ORRegion="West"Amount>500Product (AND)Sum (OR)TRUE (1)TRUE (1)1 kept2 keptTRUE (1)FALSE (0)0 dropped1 keptFALSE (0)TRUE (1)0 dropped1 keptFALSE (0)FALSE (0)0 dropped0 dropped

Step 5 of 11Practice · Choose one

Which formula returns all orders that are from the West region OR have an amount over 1,000?

Step 6 of 11Learn

SORT, SORTBY, UNIQUE and SEQUENCE

SORT(array, [sort_index], [sort_order]) sorts by a column number within the array, with 1 for ascending (default) and −1 for descending. =SORT(FILTER(Orders, Orders[Region]="West"), 4, -1) lists West orders from largest to smallest amount, if Amount is the fourth column.

SORTBY(array, by_array, [order]) sorts by any range, even one you don't return: =SORTBY(Orders[Customer], Orders[Amount], -1) lists customers by amount without showing the amounts.

UNIQUE(array, [by_col], [exactly_once]) removes duplicates. =UNIQUE(Orders[Customer]) lists each customer once. With the third argument TRUE, it returns only values that appear exactly once: customers who ordered a single time.

SEQUENCE(rows, [columns], [start], [step]) generates numbers: =SEQUENCE(12) is 1 to 12; =SEQUENCE(5,1,100,10) is 100, 110, 120, 130, 140. Wrap it in DATE to build a list of month starts: =DATE(2026, SEQUENCE(12), 1).

The functions combine naturally. A top-five list: =TAKE(SORT(Orders, 4, -1), 5), where TAKE keeps the first n rows. Because everything recalculates, the leaderboard stays current without anyone touching it.

Step 7 of 11Practice · Put in order

Excel evaluates =SORT(UNIQUE(FILTER(Orders[Customer], Orders[Region]="West"))) from the inside out. Put the steps in order.

Drag the items, or use the arrow buttons, to put them in order.

  1. SORT puts the remaining names in A–Z order
  2. Test each row: is Region equal to West?
  3. The final list spills down from the formula cell
  4. FILTER keeps the customer names from West rows
  5. UNIQUE removes repeated customer names

Step 8 of 11Learn

LET: name the pieces of a long formula

Long formulas often repeat the same calculation. This one flags orders more than 20% above the average West order:

=IF(D2 > AVERAGEIFS(D:D,B:B,"West")*1.2, "High", IF(D2 < AVERAGEIFS(D:D,B:B,"West")*0.8, "Low", "Normal"))

AVERAGEIFS appears twice, so it's calculated twice and must be edited in two places. LET assigns names to values inside a formula:

=LET(avg, AVERAGEIFS(D:D,B:B,"West"), IF(D2>avg*1.2, "High", IF(D2<avg*0.8, "Low", "Normal")))

The syntax is LET(name1, value1, [name2, value2, ...], calculation). Names are defined in pairs, each can use the names before it, and the last argument is the result. The benefits are real: the average is computed once, the formula reads almost like a sentence, and a change happens in one spot.

LET shines with dynamic arrays, where intermediate results are whole lists:

=LET(west, FILTER(Orders, Orders[Region]="West"), SORT(west, 4, -1))

For reusable custom logic, Microsoft 365 also offers LAMBDA, which turns a formula into your own named function. That's a topic for an advanced course, but it builds directly on what LET teaches.

LET computes the average once and reuses the nameavg =AVERAGEIFS(D:D,B:B,"West")D2 > avg*1.2 →HighD2 < avg*0.8 →Lowotherwise →Normal

Step 9 of 11Note

Step 10 of 11Practice · Work it out

What is the last value spilled by =SEQUENCE(4, 1, 10, 5)?

Step 11 of 11Practice · Choose one

Which statement about =LET(rate, 0.08, net, B2-C2, net*(1+rate)) is true?