Sorting a Numbers Table with Array Formulas

I have a table (Numbers 14.4) with several arrays using LOOKUP and INDEX formulas in a several columns. I want the arrays because as I add new rows of data, I want the formulas to apply to the new rows.


Columns: Date, Description, Amount, Category, Sub-Category, Month, Year


Sub-Category: IFERROR(LOOKUP($Category,Categories::$Category,Categories::Sub-Category),"")

Month: INDEX(MONTH(Date),0)

Year: INDEX(YEAR(Date),0)


However, when I try to SORT the table by the Date, I get the message that "The table contains a formula that spills its results across rows."


How do I create this table so it sorts by the Date column using the array formulas?

Posted on Oct 22, 2025 10:02 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 22, 2025 3:20 PM

Yeah, spilled results get in the way of sorting, because the order of the rows changes as you sort, which shifts where the spilled function is, and therefore messes up the results.


However, all is not lost. There are a couple of things you can try.


First off, you shouldn't need to use spilled arrays to accommodate inserted data. Assuming you enter the basic formula at the top of your table and fill down, Numbers should recognize that and copy the function down into newly appended rows.

For example, set the first cell in the Month column to simply =MONTH(@A) (or even =MONTH(A2), then select this cell and drag the yellow handle down (or select the rest of the cells in the column and choose Table -> Autofill Cells -> Fill Down).

now select the last row in the column and click to add a row below. The Month column should continue the formula from the cell above.


This approach has the advantage that you're not using spilled results, so you're free to sort the table as you like.


The second option is to separate the spilled results into a separate table. The first table has the fixed/sortable data (Date, Description, Amount and Category) while the second table has the spilled results. By aligning the tables you can get them to look like a single table. For example, this is two tables aligned:



As long as the second table has at least as many rows as the first, you can sort the first table and the second table will recalculate accordingly.


The third option is to separate your data entry from the out. Kind of built on top of the split model above, but the primary table is used only for data entry, with no regard of sort order or anything else. A separate table then uses lookups to build the formatted output.

2 replies
Question marked as Top-ranking reply

Oct 22, 2025 3:20 PM in response to begatt

Yeah, spilled results get in the way of sorting, because the order of the rows changes as you sort, which shifts where the spilled function is, and therefore messes up the results.


However, all is not lost. There are a couple of things you can try.


First off, you shouldn't need to use spilled arrays to accommodate inserted data. Assuming you enter the basic formula at the top of your table and fill down, Numbers should recognize that and copy the function down into newly appended rows.

For example, set the first cell in the Month column to simply =MONTH(@A) (or even =MONTH(A2), then select this cell and drag the yellow handle down (or select the rest of the cells in the column and choose Table -> Autofill Cells -> Fill Down).

now select the last row in the column and click to add a row below. The Month column should continue the formula from the cell above.


This approach has the advantage that you're not using spilled results, so you're free to sort the table as you like.


The second option is to separate the spilled results into a separate table. The first table has the fixed/sortable data (Date, Description, Amount and Category) while the second table has the spilled results. By aligning the tables you can get them to look like a single table. For example, this is two tables aligned:



As long as the second table has at least as many rows as the first, you can sort the first table and the second table will recalculate accordingly.


The third option is to separate your data entry from the out. Kind of built on top of the split model above, but the primary table is used only for data entry, with no regard of sort order or anything else. A separate table then uses lookups to build the formatted output.

Sorting a Numbers Table with Array Formulas

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.