MSBA-175 · Lesson 7 of 12 · 21 min
Dynamic arrays and LET
▶ Video coming soon A video version of this lesson is on the way.
In the third week of October, Rosalind asked for something that used to take Dagny half a day each month: a live list of every booking with a balance still owing, sorted so the largest amounts came first, on a sheet she could open on her phone. In older Excel that meant an Advanced Filter run by hand or a macro. In Microsoft 365 it is one formula, because of dynamic arrays. The exam lists two of the dynamic array functions by name, FILTER() and SORTBY(), alongside RANDARRAY from lesson 2 and LET from lesson 5. This lesson covers how dynamic arrays behave, those functions in depth, and the related functions you will meet in real workbooks.
Spilling
A formula that returns more than one value spills: the results flow into the cells below and to the right of the formula cell, which together form the spill range. Only the top-left cell contains the formula; the other cells show results but are greyed in the formula bar and cannot be edited on their own. Selecting any cell in a spill range draws a blue border around the whole range.
Two pieces of notation come with spilling. The # after a cell reference, as in =SUM(F2#), refers to the entire spill range that starts at F2, however large it currently is. And the @ operator, the implicit intersection operator, forces a formula to return a single value; Excel sometimes adds it automatically when it opens a workbook created in an older version, to preserve the old behaviour.
If the cells a formula needs are not empty, the formula returns #SPILL! and shows nothing. Selecting the error shows a dashed outline of the range it wants, and the error button offers Select Obstructing Cells. Clearing those cells makes the result appear. Spilled formulas also cannot be placed inside an Excel table, because tables expand row by row; put them next to the table or on another sheet. #SPILL! can also mean the result is too large for the sheet, or that the formula refers to an entire column in a way that would spill a million rows.
FILTER
FILTER returns the rows (or columns) of an array that meet a condition. It takes three arguments: the array, an include argument of TRUE and FALSE values the same height as the array, and an optional value to return if nothing matches.
=FILTER(Bookings, Bookings[Status]="Overdue", "No overdue bookings")
=FILTER(Bookings[[Client]:[Fee]], (Bookings[Package]="GG")*(Bookings[Guests]>100))
=FILTER(Bookings, (Bookings[Status]="Overdue")+(Bookings[Status]="Due later"))
=FILTER(Bookings[Client], ISNUMBER(SEARCH(L2, Bookings[Notes])))Conditions in FILTER are combined with arithmetic, not with AND and OR. Multiplying two arrays of TRUE and FALSE values gives 1 only where both are TRUE, which acts as AND. Adding them gives a non-zero value where either is TRUE, which acts as OR. The AND and OR functions do not work here because they return a single TRUE or FALSE for the whole array instead of one value per row.
Without the third argument, FILTER returns #CALC! when no rows match, which is Excel's error for an empty array. Rosalind's phone view used the third argument so it showed "All paid" on good days instead of an error.
SORT and SORTBY
SORT sorts an array by one of its own columns. SORTBY sorts an array by one or more other arrays, which do not have to be part of the result. That difference is why the exam names SORTBY: it can sort by a column you are not displaying, and it can sort by several keys in different directions.
=SORT(FILTER(Bookings[[Client]:[Balance]], Bookings[Balance]>0), 4, -1)
=SORTBY(Bookings[Client], Bookings[Balance], -1)
=SORTBY(Bookings[[Client]:[Event date]], Bookings[Status], 1, Bookings[Event date], 1)| Function | Arguments | Sort order values |
|---|---|---|
| SORT | array, [sort_index], [sort_order], [by_col] | 1 ascending (default), -1 descending |
| SORTBY | array, by_array1, [sort_order1], [by_array2, sort_order2], … | 1 ascending (default), -1 descending |
Each by_array in SORTBY must be the same height as the array being sorted (or the same width when sorting columns). Using whole table columns guarantees that. Rosalind's phone sheet became one formula in A2 of a new sheet: =SORTBY(FILTER(Bookings[[Client]:[Balance]],Bookings[Balance]>0,"All paid"),FILTER(Bookings[Balance],Bookings[Balance]>0),-1). It is correct but repetitive, which is exactly the situation LET was designed for.
LET with dynamic arrays
LET names an array once and reuses it, which removes the repetition and makes the formula readable.
=LET(
owing, Bookings[Balance]>0,
rows, FILTER(Bookings[[Client]:[Balance]], owing, "All paid"),
amounts, FILTER(Bookings[Balance], owing),
SORTBY(rows, amounts, -1))Each name can use the names defined before it, so a LET formula reads like a recipe: define the condition, use it to pick rows, use it again to pick the sort key, return the sorted rows. The finished formula recalculates whenever a booking changes, and Rosalind's view is always current.
Worked problem
Top five venues by revenue
Rosalind wants the five venues with the highest 2027 booked revenue, largest first, as a live list. The Bookings table has Venue, Event date and Fee columns. Build it with dynamic arrays.
Show solution
- Get the distinct venues: UNIQUE(Bookings[Venue]).
- Total each venue's 2027 fees with SUMIFS, which accepts an array as its criteria and returns one total per venue.
- Sort the venues by those totals with SORTBY, descending.
- Keep the first five rows with TAKE, and wrap the whole thing in LET.
Answer: =LET(v,UNIQUE(Bookings[Venue]),t,SUMIFS(Bookings[Fee],Bookings[Venue],v,Bookings[Event date],">="&DATE(2027,1,1),Bookings[Event date],"<"&DATE(2028,1,1)),TAKE(SORTBY(HSTACK(v,t),t,-1),5)). It spills five rows of venue and total.
Other dynamic array functions
Microsoft 365 has a family of functions built for arrays. Only some are named on MO-211, but you will see the others in tasks that ask for a result without naming the function, and in real workbooks.
| Function | What it returns | Example |
|---|---|---|
| UNIQUE | Distinct rows; optionally those that appear once | =UNIQUE(Bookings[Venue]) |
| SEQUENCE | A grid of sequential numbers | =SEQUENCE(12,1,1,1) for months 1 to 12 |
| RANDARRAY | Random numbers | =RANDARRAY(10,1,1,100,TRUE) |
| TAKE / DROP | The first or last rows, or all but them | =TAKE(list,5) |
| CHOOSECOLS / CHOOSEROWS | Selected columns or rows | =CHOOSECOLS(Bookings,2,7) |
| VSTACK / HSTACK | Arrays stacked vertically or side by side | =VSTACK(Q1list,Q2list) |
| TEXTSPLIT | Text split into columns or rows | =TEXTSPLIT(B2,", ") |
SEQUENCE is the quiet workhorse. Combined with DATE, =DATE(2027,SEQUENCE(12),1) spills the first day of each month of 2027, and =EOMONTH(DATE(2027,1,1),SEQUENCE(12)-1) spills the last days. Dagny used the second as the header row of the budget by wrapping it in TRANSPOSE, so the months ran across the sheet.
UNIQUE has two optional arguments worth knowing. The second, by_col, compares columns instead of rows. The third, exactly_once, returns only the values that appear exactly one time, which is different from distinct values. =UNIQUE(Bookings[Client],,TRUE) lists clients who have booked only once, which Rosalind used for a "come back to us" mailing. Applied to several columns at once, such as =UNIQUE(Bookings[[Client]:[Package]]), UNIQUE treats each row as a whole, so a client who booked two different packages appears twice. As with every function in this family, the result is live: when a one-time client books again, their name drops off the list on the next calculation.
Legacy array formulas
Before dynamic arrays arrived, Excel supported array formulas that had to be confirmed with Ctrl+Shift+Enter. Excel showed them with curly braces around the formula, as in {=SUM(IF(Bookings[Status]="Paid",Bookings[Fee]))}, and a multi-cell array formula had to be entered into a range of exactly the right size selected in advance. Those formulas still work in Microsoft 365, and you will meet them in older workbooks. You cannot edit one cell of a multi-cell legacy array; Excel says you cannot change part of an array, and you must select the whole range to edit or delete it.
There is rarely a reason to create new ones. Any formula that once needed Ctrl+Shift+Enter now works with Enter, and if it returns several values it spills. When Dagny found a legacy array in the 2019 commission workbook, she selected its range, deleted it, and re-entered the same formula once in the top-left cell, where it spilled to the correct size and would grow with the data.
Building a dynamic report sheet
The real value of dynamic arrays appears when several formulas work together on one sheet. Dagny's "Season at a glance" sheet for Rosalind has no copied-down formulas at all. Cell A2 holds =SORT(UNIQUE(Bookings[Package])), which spills the package codes. B2 holds =COUNTIFS(Bookings[Package],A2#), which spills one count beside each code because its criteria argument is a spill range. C2 holds =SUMIFS(Bookings[Fee],Bookings[Package],A2#), and D2 divides them with =C2#/B2#. When a new package is added to the table, every column grows by a row on its own.
| Cell | Formula | Spills |
|---|---|---|
| A2 | =SORT(UNIQUE(Bookings[Package])) | One row per package code |
| B2 | =COUNTIFS(Bookings[Package],A2#) | Bookings per package |
| C2 | =SUMIFS(Bookings[Fee],Bookings[Package],A2#) | Revenue per package |
| D2 | =C2#/B2# | Average fee per booking |
This pattern, one spilling list of keys and other formulas that refer to it with #, replaces many simple PivotTables for quick summaries. It is not a replacement for PivotTables when people need to rearrange fields, filter interactively or drill into details, which lesson 10 covers. Dagny uses formulas for fixed layouts that feed charts and PivotTables for exploration.
Performance and good habits
Dynamic array formulas recalculate whenever their inputs change, and functions such as FILTER over a large table can be expensive if repeated in many places. Three habits keep workbooks fast. Calculate a spilled list once and refer to it with # rather than repeating the same FILTER in several cells. Use LET inside a formula that needs the same array twice. And refer to table columns rather than whole worksheet columns, so Excel works only with the rows that exist. With these habits, the season workbook, with its phone view, its summary sheet and 430 bookings, still recalculated instantly on Rosalind's laptop.
Working with spilled results
Other formulas can refer to a spill range with the # operator, and they adjust automatically as it grows. =ROWS(A2#) counts the unpaid bookings. =SUM(D2#) totals their balances. A chart, a data validation list (lesson 4) or a conditional formatting rule can also point at a spill range. Formatting does not follow a spill range automatically, though: if the list grows from 12 rows to 20, the extra rows have no formatting unless you formatted generously ahead or used a conditional formatting rule that covers the larger area.
Spilled formulas can be referenced from other workbooks only while both are open, and a workbook that uses dynamic arrays opened in Excel 2019 or earlier shows the old array formula behaviour with fixed-size results. Since Maple & Pine uses Microsoft 365 everywhere, Dagny relies on them freely.
Worked problem
A spill range that broke
Teo typed a note in cell C9 on Rosalind's phone sheet. Now A2 shows #SPILL! and the whole list has disappeared. How does he find and fix the problem?
Show solution
- Select A2 and look at the dashed border showing the range the formula needs.
- Click the error button and choose Select Obstructing Cells; Excel selects C9.
- Move the note to a cell outside the spill range, such as the row above the list.
- Confirm the list reappears and spills to its full size.
Answer: A spilled formula needs every cell in its range to be empty. Removing the obstruction restores the result immediately.
Common mistakes
MistakeUsing AND or OR inside FILTER's include argument.
InsteadMultiply conditions for AND and add them for OR.
MistakeTyping into a cell inside a spill range.
InsteadLeave spill ranges empty; edit the formula in the top-left cell.
MistakePutting a spilling formula inside an Excel table.
InsteadPlace it next to the table or on another sheet.
MistakeReferring to a fixed range like D2:D20 for a spilled result.
InsteadUse D2# so the reference grows with the spill range.
MistakeLeaving out FILTER's if_empty argument.
InsteadGive a message so an empty result does not show #CALC!.
Summary and key terms
- Dynamic array formulas spill their results; # refers to a whole spill range and @ forces a single value.
- #SPILL! means something blocks the spill range; Select Obstructing Cells finds it.
- FILTER returns matching rows; multiply conditions for AND, add them for OR, and supply an if_empty value.
- SORT sorts by its own columns; SORTBY sorts by other arrays and by several keys.
- LET names arrays and steps so dynamic array formulas stay short and readable.
- Spill range
- The cells filled by a formula that returns more than one value.
- Spill reference
- A reference with # that refers to an entire spill range.
- #SPILL!
- An error shown when a formula's spill range is blocked or invalid.
- FILTER
- A function that returns the rows of an array that meet conditions.
- SORTBY
- A function that sorts an array by one or more other arrays.
- Implicit intersection
- Reducing a range to a single value, shown by the @ operator.
Practice problems
Work each problem on paper first, then reveal the answer to check.
How do you refer to the whole spill range starting at F2?
Show answer
F2#
How do you combine two FILTER conditions as AND?
Show answer
Multiply them: (cond1)*(cond2).
Which function sorts by a column that is not in the result?
Show answer
SORTBY.
What does FILTER return when nothing matches and no if_empty value is given?
Show answer
#CALC!
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.