Google Sheets – How to Reference the Last Column in a Sheet

google sheets

Each week I add a new column to a spreadsheet and then need to update several formulas to calculate the delta between the last column and the column to the left of it.

I haven't figured out a way to get the value from that column so i can do math on it. The other solutions i found would let me reference that column…

enter image description here

Best Answer

To determine the last column, one should decide in what row to measure it. Suppose it's the 2nd row; then the last column number is

=max(filter(column(K2:2), len(K2:2)))

where I put K to avoid circular dependency, since this formula will also affect some cells in row 2, to the left of column K. I'd put the above formula in some cell, e.g., E1 (or on another sheet), and then use it in computations like this:

=arrayformula(filter(K2:27, column(K2:2)=E1) - filter(K2:27, column(K2:2)=E1-1))

This takes the difference between the last and second-to-last columns.

Instead of filter, one could incorporate column number in formulas by using indirect with R1C1 notation, but that seems more complicated to me.