9. Dynamic Arrays
Turn a repeated table export into a live answer
A fictional grocery coordinator wants a current list of delivered Nashik orders that took more than twelve minutes. It should show the most expensive order first. Yesterday the coordinator filtered the source, used a sort and copied the matching rows to a different tab. That copy was useful until the next order arrived. Today they want a formula output they can verify as source data changes. Dynamic arrays give them a way to calculate a list in a separate worksheet region using formulas.
An array is a row or column of values, or a rectangular collection of rows and columns. A classic one-cell result such as SUM can read an entire array and return one amount. A dynamic array formula can return several values and can change the output’s dimensions as its inputs change. When that output needs several cells, Excel places the values in adjacent cells from a starting cell. This is called spilling. The cell containing the formula is its anchor. The cells occupied by its calculated values are its spill range.
Use the examples as practice only. The first lab follows a small grocery queue with Blinkit and Amazon Now labels, and the second uses a made-up variation of the Chapter 3 source. The figures and timing rules have no connection to those businesses. In the second lab, “late” means a practice threshold on measured minutes. There is no claim about a service commitment or a particular clock time.
Learn the chapter in stages
Start with the small formulas whose result you can predict before opening Excel. Once you can explain where the output will appear, add a second operation. A sorting or filtering function is easier to debug when you can verify its input shape and result on their own. The later lessons apply the same idea to reports, messy identifiers, images and reusable functions.
Spills and core list operations
- Spill Ranges and the # Operator lets you describe the whole live result from its anchor and identify a blocked output.
- FILTER pairs each input record with a matching TRUE or FALSE test and defines a safe empty-result message.
- SORT and SORTBY order result rows without asking you to rearrange the source sheet.
- UNIQUE answers distinct-value questions and distinguishes a distinct list from values that occur only once.
- SEQUENCE and RANDARRAY generate arrays you can use to practice sizes, positions and sample behavior.
- LET names intermediate steps, such as a row test or subtotal, inside an expression.
- LAMBDA introduces the idea of giving a calculation its own inputs and testing one call.
Make the result fit its reporting task
- VSTACK and HSTACK join blocks vertically or horizontally by position. Verify labels or keys before combining information.
- CHOOSECOLS, TAKE and DROP select fields or parts of a result, including decisions about whether the input contains headings.
- GROUPBY makes a grouped summary once you specify the fields, aggregation and header policy.
- PIVOTBY and PivotTable compare a formula-shaped matrix and a report object, including distinct layout and interaction options.
- REGEXTEST, REGEXEXTRACT and REGEXREPLACE apply patterns to text values you need to validate or pull apart.
- TOCOL and TOROW flatten a grid with a planned scan direction and policy for empty or error entries.
- WRAPROWS and WRAPCOLS reshape one list into a predictable grid.
- EXPAND pads an array to a requested size where the receiving layout needs consistent dimensions.
- TRIMRANGE and the Trim Ref Operator work with empty outer rows or columns rather than removing an internal gap.
- IMAGE adds supported pictures from suitable sources inside worksheet cells.
Package reusable calculations after testing them
- Named LAMBDA and ISOMITTED document reusable workbook names and distinguish omitted arguments from explicit zero.
- MAP, REDUCE, SCAN, BYROW, BYCOL and MAKEARRAY choose the output shape based on how you want to repeat or accumulate a calculation.
- Recursive LAMBDA places a clear stopping condition and safety checks before building a reusable function library.
- Apply the ideas in the core practice and newer functions practice. Each answer should identify both the output dimensions and the underlying data.
Check function availability at the level of the formula
Spilling is a calculation behavior. Availability of a particular formula is another question. Current Microsoft documentation lists foundational functions such as FILTER, SORT, SORTBY, UNIQUE, SEQUENCE, RANDARRAY and LET in supported Excel 2021 and later editions, as well as applicable Microsoft 365 releases. The functions catalogue uses a newer edition marker for functions such as VSTACK, TAKE, IMAGE and LAMBDA. Some newer functions in this chapter, such as GROUPBY, PIVOTBY and TRIMRANGE, have a Microsoft 365 marker in the catalogue. Check the individual function, client and installed build when planning a workbook for other people. A broad documentation header can list more versions than the function itself is documented for.
Try a small formula from each function family on the same device you will use for the lab. For example, test =SEQUENCE(2) outside any Table in a free area and verify two outputs. If the application shows an unrecognized function or an _xlfn. prefix in a file, check the edition and feature availability before trying to fix an unrelated sheet setting. A formula that another user can calculate should still be tested in the target client if they need to edit or refresh it. Choose a verified static values copy or use earlier tools such as a Table filter when the recipient needs a stable result in a different Excel version.
Lab 1. Make one formula return four complete records
In a scratch sheet named Sample, type these four order records in A1:D5. The compact list makes it possible to test the complete result by hand. The IDs are made-up labels. Enter all four Amount entries as numbers. Reserve F1:I7 for output and put any check formulas elsewhere, for example in K2:K5.
| Order | City | Platform | Amount |
|---|---|---|---|
| O101 | Pune | Blinkit | 100 |
| O102 | Mumbai | Amazon Now | 300 |
| O103 | Pune | Amazon Now | 200 |
| O104 | Pune | Blinkit | 400 |
Predict the input and output dimensions
- Copy the headings separately. Put Order, City, Platform and Amount in F1:I1. The source data body is A2:D5, with no headings. Using A1:D5 would mix a header into the records being sorted. Keep the sort input and output headings distinct.
- Enter the calculation once. In F2 enter
=SORT(A2:D5,4,-1). SORT treats the fourth column in the supplied array as its sort key. The minus one requests descending order. The sorted output should display O104, O102, O103 and O101, with their other fields matching their source rows. The physical source order stays O101, O102, O103 and O104. - Read the full output address. The first result is F2. Four columns fill F through I and four records fill rows 2 through 5.
F2#refers to that current spilled result as a single reference. Try=ROWS(F2#),=COLUMNS(F2#)and=COUNTA(F2#)in separate Check cells. Expect 4, 4 and 16. COUNTA reads populated cells in the whole rectangle. It does not count only the IDs. - Check one rupee amount by its source record. The top amount is 400 and its ID is O104. O104’s city is Pune and its platform is Blinkit. Verify those values appear with it after sorting. A list of four amounts could look sorted and still be unhelpful without the corresponding order fields.
- Test growth on purpose. Change O101 Amount to 500. The output now begins with O101, then O104, O102 and O103. Its shape stays four by four. Restore 100. Appending a fifth record at row 6 does not automatically expand the fixed A2:D5 input. Update that input on purpose or use a Table source if its membership is intended to grow.
Make Excel show the boundary of a blocked result
Go to a new scratch region such as M2:P6. Type Keep this note in P4. In M2 repeat the same SORT formula. The intended output is M2:P5, so the note sits inside the destination even though it is neither input nor formula. The anchor shows a spill error. Select that cell to inspect the indicated spill range. If your Excel client offers Select Obstructing Cells, use it to locate the blocker. Move the note to an independently labeled cell such as R4. The result can then fill M2:P5. You have fixed the output layout without changing the source data or the sort condition.
Try to review the formula at the anchor rather than treating each output cell like an independent editable cell. To edit the rule use M2. A result cell such as P4 is generated by M2 after the note is moved. If a colleague needs to add comments next to the result, put them in a reserved area and include the actual order ID. A note keyed only to worksheet row 4 could suddenly describe a different order after the result is sorted again.
Distinguish the number of rows from the number of matches
The original SORT always returns four data rows in this fixed exercise. That makes ROWS(F2#) a useful count of the returned records. Later a FILTER formula can return a single text message when nothing qualifies. One message occupies a cell, but it is not a matching order. Keep an independent count of the criterion when no matches are possible. To measure the current data, ask which result row represents a record before adding a count.
Lab 2. Build a live report from a growing Table
This is an abbreviated practice variation of the Chapter 3 order list. In a scratch sheet called Data enter these six fictional records below their headings. Use numeric Amount and Mins. The lab compares delivered orders from one city to a practice threshold: keep a delivery if Mins is strictly greater than the threshold. A cancelled order with a number recorded in Mins stays out of this report.
| Order ID | City | Amount | Mins | Status |
|---|---|---|---|---|
| BLK-1001 | Pune | 64 | 9 | Delivered |
| BLK-1002 | Nashik | 270 | 12 | Delivered |
| BLK-1004 | Nagpur | 240 | 11 | Cancelled |
| BLK-1006 | Pune | 150 | 8 | Delivered |
| BLK-1007 | Solapur | 1299 | 18 | Delivered |
| BLK-1010 | Nashik | 90 | 17 | Delivered |
Start with a separate source and report layout
- Create the source Table. Convert Data A1:E7 to an Excel Table with headers and name it
tblDynamicwhere supported. If you use a different name, update every reference to that object. Verify six actual data rows. - Place two report parameters. On another worksheet named Dispatch, put City in A2 and Nashik in B2. Put Minutes above in A3 and numeric 12 in B3. Copy the five source headings to A5:E5. Leave A6:E20 empty so the report has room to grow.
- Calculate the independent count. Put Matching orders in A4 and
=COUNTIFS(tblDynamic[City],$B$2,tblDynamic[Mins],">"&$B$3,tblDynamic[Status],"Delivered")in B4. This uses criteria from settings, rather than counting the size of a message on the report. With the original source, B4 should be 1. - Enter the report formula once. Paste the expression below into A6 on a client with LET, FILTER and SORT available. The formula identifies its source, makes one inclusion value for each record and checks whether any match before sorting. Use your client’s formula argument separator if it differs from commas.
=LET(sourceRows,tblDynamic[[Order ID]:[Status]],
keepRows,(tblDynamic[City]=$B$2)*(tblDynamic[Mins]>$B$3)*(tblDynamic[Status]="Delivered"),
IF(SUM(keepRows)=0,"No matching orders",SORT(FILTER(sourceRows,keepRows),3,-1)))
LET gives names to two steps inside this expression. sourceRows is the five-column data rectangle. keepRows is a one-column set of row tests. Each comparison supplies TRUE or FALSE. Multiplication yields 1 for a record only if all three comparisons are true. COUNTIFS on the check line works independently from that expression. With clean typed inputs it should agree with the count of ones. If there are no ones, return a plain message. If there are matches, FILTER picks those rows and SORT reads the third output field, Amount, to rank them highest first.
The no-match branch is important. If FILTER were asked to return the message as its third argument and you then always tried to sort that message by its third column, the sort would have only a single cell as input. The outer test selects between a text message and a five-column data result. This is why the report uses an explicit independent count in B4. A report whose shape can change has to explain what each shape means.
Test a boundary, a new record and a true zero-match view
- Read the original result. At a cutoff of 12 for Nashik, BLK-1010 at 17 minutes and ₹90 is the one matching record. BLK-1002 at 12 minutes does not meet the strictly greater-than test. Read the exact ID and amount, as well as the one-row count.
- Add an eligible Table member. In Data append BLK-1011, Nashik, 367, 15, Delivered. Make sure Excel actually includes the row in the source Table. Anticipate two report rows totaling ₹457, with the new amount ₹367 first and existing ₹90 second. B4 should give 2. The first output order changes because the rank is based on the latest source.
- Lower the cutoff to 11. Change Dispatch B3 to 11. BLK-1002 now qualifies. The three results appear as BLK-1011, BLK-1002 and BLK-1010 with amounts ₹367, ₹270 and ₹90. They total ₹727. The prior boundary record now provides a precise check that the input control really works.
- Test an unlisted city. Enter Delhi in B2. The count should be zero and the anchor shows one status message. Reenter Nashik and restore threshold 12 at the end. Check if there is space for the original two matching rows to return.
Predict the report before changing the workbook
Find deliveries strictly over twelve minutes
For Nashik, BLK-1010 passes at 17 minutes and ₹90. BLK-1002 is exactly 12, so it stays outside the result.
Append a second match
BLK-1011 joins at 15 minutes and ₹367. It appears first after sorting because Amount controls the order.
Lower the threshold
At 11 minutes, the original 12-minute row also passes. The matching count is 3 and the amounts add up to ₹727.
Choose an unlisted city
The report shows one message. Matching orders reads zero. Read the count rather than assuming each displayed row represents an order.
Inspect a formula in stages before combining it
Make a small truth table for your conditions
Use the four orders in Sample to test a simple example. The report asks for Pune orders above ₹150. Check the city for each record, then check the amount. Where both are true, keep it. Write the test result next to the record in a separate scratch area first. This is a useful way to debug a difficult formula because you can tell whether a problem arose in the selection step or in the later ordering step.
| Order | Pune? | Amount >150? | Keep? |
|---|---|---|---|
| O101 | True | False | No |
| O102 | False | True | No |
| O103 | True | True | Yes |
| O104 | True | True | Yes |
On Sample use a new clear region, or first remove the test formula on M2 if you no longer need it. Enter =FILTER(A2:D5,(B2:B5="Pune")*(D2:D5>150),"No matching orders"). The filtered data arrives in the original source order, so you should see O103 at ₹200 followed by O104 at ₹400. Then test a separate SORT expression on that matching result, for example =SORT(M2#,4,-1) if FILTER starts at M2 and those two data rows are present. Now the order is O104 and O103. The total remains ₹600. The filter is responsible for selection. The sort is responsible for sequence. Verify each before combining them in a production-style formula.
One condition must align with every intended source row. B2:B5 and D2:D5 have the same height as A2:D5, and their first entries describe the same first record. If you accidentally use B3:B6 and D2:D5, the dimensions still look compatible. The first city test now belongs to O102 while the first amount belongs to O101. These tests have moved out of alignment and can produce a plausible wrong list. Size is necessary, and correspondence by actual record is also necessary.
Use each function for the output shape you need
- List matching orders. FILTER keeps source records or fields according to its aligned tests. Check an included and excluded row.
- Rank complete records. SORT uses the sort column’s position in the selected array. SORTBY can use separate aligned keys. Keep all fields needed by the report together inside the output array.
- Make a list of choices. UNIQUE can return distinct cities. In the four original rows, Pune contributes one choice and Mumbai another. Its once-only option answers a different question and yields Mumbai only here.
- Generate a test shape. SEQUENCE creates predictable numeric values. Test
=SEQUENCE(4,1,101,1)in a clear spot for 101, 102, 103 and 104 in one column. RANDARRAY supplies a random test array when variability is actually needed. - Label a calculation stage. LET lets you name the matched set or threshold once. LAMBDA lets you define a calculation you can call with your own inputs. Practice short definitions with known answers before joining several stages together.
- Join or reshape a source. Stacking functions use the cells’ positions. Make sure a combined block has the same interpretation for fields at those positions. A wider grid might not put two orders with the same ID side by side unless you deliberately align them first.
Plan for changes to both the source and the result
Keep one clean source and one separate output
A Table is a useful place to store one record per row. Its named data fields can follow actual Table membership. A multi-cell spill formula belongs in the worksheet grid outside the Table. When the source and output sit close together, the next Table row or formula output can collide with other content. A separate output tab makes space and purpose clearer. Put controls above the result and deliberate notes outside the spill footprint. Do not put a future summary directly below a result whose number of rows can grow.
If your dynamic formula refers to a different workbook, Microsoft documents limited support when both workbooks are open. When the source workbook is closed, refreshing a linked dynamic array can return #REF!. Do not assume a report works as a standalone file because it calculated once with both files open. Keep a verified source copy in the same workbook or plan a documented import for reports that must work independently. If someone only needs the result at a particular time, a checked static export may fit the request.
Understand the difference between a visible source and a formula result
Filtering the source Table through a header or slicer changes its view. A formula such as FILTER reads the explicit include condition you wrote and the data it references. It does not automatically inherit the reader’s current Table header selections. For example, a report using tblDynamic and a City parameter of Nashik still asks for Nashik if you click Pune in the source Table’s header. This is valuable for a stable report, and it is also a source of confusing discrepancies when its label simply says “current view.” Document which input drives it.
Keep your record counts independent from formatting and placeholders
If blanks appear in a returned column, inspect their stored meaning on the source and the calculation’s formatting. A blank from the referenced source can appear as a zero in an output. A formula returning an empty string is a stored cell expression with a distinct meaning from an unused cell, and it can obstruct a spill even when the cell looks blank. Plan how you want missing fields to display. Avoid turning all zero amounts into missing values, because zero can mean an actual recorded event. A formula report can keep a separate quality count or flag to explain how many values are known.
Once the view works, test both a change that leaves its shape alone and a change that expands or shrinks it. Editing O101’s amount changes the order of four records while keeping all four. Adding BLK-1011 as a new matching member changes the number of report rows. Entering Delhi in the report settings empties the selection and returns a message. These outcomes establish the dimensions and record counts the workbook needs to support.
Read a formula failure according to the stage that produced it
Start by checking the intended stage and output
- Input range. Verify it contains the intended records and excludes headings when the function expects data only. A reference such as A2:D5 remains fixed even if more records are typed below it.
- Condition. Check the corresponding value for each intended row or column. Inputs of equal length can still be shifted. Verify the first and last record by ID and check whether any criteria cell is an error value.
- Operation. Identify whether it should filter, group, rank, reshape or calculate a single measure. Check arguments such as which column index a sorted output actually contains.
- Anchor and destination. Locate the exact formula cell and outline where its results should appear. Check that neither an existing Table nor a merged cell or note blocks the output.
- Recipient’s check. Decide which exact values or IDs prove the result. A screenshot showing two numbers does not establish that the output loaded in a different Excel version or that it captured all matches.
| Observation | First check | Small control |
|---|---|---|
| Spill error at the anchor | Blocked or invalid destination | Move one known note outside the expected rectangle. |
| FILTER has no results | Match count and empty-result policy | Test a known city and then an unlisted city. |
| Fields or order are wrong | Shape and key alignment | Inspect the input rectangle and a complete returned ID. |
| A linked report stops refreshing | Source availability and workbook compatibility | Check the intended source workbook state. |
| Appended record stays absent | Input membership or remaining rule condition | Test the Table boundary and the record’s values. |
Give a shape-changing result a second, clear output for consumers
Suppose the Sample report later needs only Order and Amount. A newer Excel client that supports CHOOSECOLS can select the first and fourth input columns. With the original four rows =CHOOSECOLS(A2:D5,1,4) returns four rows and two columns. If you then sort that chosen result by amount, the amount is now its second column. A sort key of 4 described the original list, not the narrowed result. For example, =SORT(CHOOSECOLS(A2:D5,1,4),2,-1) gives O104 and 400 first, followed by the same descending order as the original lab. Count four order rows and eight populated cells from that smaller rectangle.
This is a shape check as well as a data check. The formula itself does one selection and then one sort. Use individual test cells to inspect the intermediate selected columns before joining the steps. When columns need to travel with a particular ID, do the selection from a correct aligned input. If a separate report already reordered the IDs, positional stacking will not recover which records correspond. Use a verified key-based lookup for that task.
Save a value snapshot when the decision is time-bound
After the Nashik append test with the 12-minute threshold, make an independent snapshot in a practice workbook or on a clean worksheet. In this case the result is exactly two rows and five fields, so confirm the full spill and its separate headings before copying. Paste the output as values. Check that it contains BLK-1011 at ₹367 and BLK-1010 at ₹90 in the stated order, with the matching cities and timings still attached. Write down the data version and rule used for the extract. The output means “delivered Nashik orders over twelve minutes at the time this snapshot was made.”
Then change the live cutoff to 11. The live report adds BLK-1002 at ₹270 and its count becomes three. Your separate values copy should still contain two IDs. That difference is intentional. Inspect a destination cell’s formula bar and verify it stores an independent value. If the recipient expects a recalculating report, a values copy alone cannot provide that. Decide which use the receiver needs and test the actual format you plan to share.
You can practice the same distinction when the formula shows a message. Set City to Delhi. If the intended handoff is a list of order records, there are no data rows to paste. Put the header and a separate note that the result was empty. Do not place a message in the middle of an order ID field and let a downstream report count it as a record. A useful report distinguishes the output shape from the kind of item each cell represents.
Label the current report threshold beside the input cell and keep the snapshot’s threshold in its own metadata cells. One label describes a live setting and the other describes a test already performed. Exact period and threshold wording help a reader compare the prior record set with the present one.
Return the practice workbook to Nashik and 12 minutes before closing. Compare the visible live IDs, independent selected count and source membership. Keep the values copy only in the exercise. Being able to reconstruct the live and fixed results from the same original data makes it easier to debug later lessons on stacking and reshaping outputs.
Set the scale of a useful example before optimizing
Use four to ten records when first validating a formula. A long workbook can involve gaps, formulas with error values or repeated keys that make the first version harder to read. Select representative examples: one passing record, one failing record at the boundary, one expected empty case and one row you can add. Once the result agrees for those examples, expand the source deliberately. Limit input references to the actual intended source so the formula is not asked to return an entire worksheet column into a partly occupied grid.
Quiz. Predict the result before you enter it
What is the anchor if the SORT formula is entered in F2?
F2 is the anchor. It contains the editable formula. The four-by-four output in the lab fills F2:I5 from that point. F2# refers to the successful current spill rather than only the anchor’s first value.
Why does COUNTA give 16 when there are only four returned orders?
The output includes four populated fields for each of four rows. COUNTA counts populated cells. ROWS returns the number of rows. Use an independent criteria count if a visible output can be a message instead of a data row.
Which source record is exactly at the twelve-minute boundary?
BLK-1002 is a delivered Nashik order with 12 minutes. Strictly greater than 12 excludes it. Lowering the cutoff to 11 includes it. That single row is direct evidence for the intended comparison.
Which edit can expand a Table-based result?
Adding BLK-1011 to the actual Table introduces a new passing row. The output grows to two rows and sorts its ₹367 amount above ₹90. A row that is typed below the Table without becoming a record would not supply that new result.
Why does a note at P4 prevent a four-by-four spill anchored at M2?
The required area is M2:P5. P4 is inside it. Move the note to an independent place and check that the original formula spills. The calculation does not need a different sort direction.
What happens after selecting an unlisted city?
The matching count is zero and the formula shows a text message. That message makes the no-record result understandable. It is one display value rather than an additional order.
Interview practice. Explain a workbook’s changing shape
When would you use a spilled result rather than sort the source?
Use a separate formula result when the source should keep its original sequence and a readout should be calculated from current inputs. In Sample the original IDs remain in entry order, while F2 returns them highest amount first. Verify entire records and leave clear output space.
Why put a live source in a Table but the formula outside it?
The Table supplies named data fields and a defined source boundary that can grow. Excel’s multi-cell spill output needs ordinary grid cells. Put the formula on another sheet or beyond the Table’s future extent so it can grow without blocking the data.
How would you explain a conditional expression inside LET?
LET names the source and the inclusion tests. The tests must align with source rows. After checking the matching count, the expression can produce a report or a status message. The names let you discuss each stage with one small expected result.
Does sorting or filtering a Table through its header automatically change a FILTER formula elsewhere?
The Table menu changes what the reader sees in that view. The formula applies its explicit include tests to the referenced data. A sort can change source row order, which can matter for order-sensitive formulas. The rows chosen by the formula still depend on the formula’s own conditions.
How would you deliver this result to someone on a different Excel version?
Check the exact functions and intended client first. To deliver an agreed result without interactive recalculation, make a verified values copy of the relevant fields with its source period and criteria. If the recipient needs to change the result, test a supported native filter or formula workflow before delivery.
Revision cards
- Anchor. Enter or edit the multi-cell formula in one starting cell.
- Spill. Leave enough clear cells for the current and future data dimensions.
- Hash reference. The anchor followed by # refers to the complete current spill.
- Alignment. Every row condition should describe the same record as the corresponding source row.
- No matches. Give readers a message and a separate actual match count.
- Version. Verify the specific function in the client where the report will be used.