I was trying to build a formula that can SPILL to return all unique text rows in a column apart from the first (header).
I found a solution at https://superuser.com/a/1259946/1137272 which works and gives me what I need using the INDEX function - which is great and I've successfully translated it from the SUM() application described into my application with UNIQUE(), but I'm having trouble understanding how it achieves the result.
The solution as provided is
=SUM(A2:INDEX(A:A, ROWS(A:A)))
in my case this translates to the functioning but more complex:
=UNIQUE(FILTER('SheetName'!D2:INDEX('SheetName'!D:D,ROWS('SheetName'!D:D)),ISTEXT('SheetName'!D2:INDEX('SheetName'!D:D,ROWS('SheetName'!D:D)))))
I follow that ROWS(A:A) gives the last row number (1048576 in my case). INDEXing by N into an array returns the Nth value in the array, so I would assume INDEX would return the value of A1048576 - in my case an empty cell, and the SUM formula would expand to SUM(A2:[blank]) or SUM(A2:0) and thus give an error.
However, this isn't what happens - apparently there's also a 'reference' form of the INDEX function and somehow INDEX knows to return the cell reference rather than the value of the cell, but I don't understand how this is triggered. It looks to me like the syntax for both forms is exactly the same:
INDEX(array/reference, row_num, [optional_arguments])
In cases like this where an array and reference look identical (A:A), how does it know when to return the value and when to return the cell reference?