## Explanation

The core of this formula is based on another formula that calculates the "current row" in a range:

```
=ROW()-ROW(rng.firstcell)+1
```

In brief, we get the current row in the workbook, then subtract the first row number of the range plus 1. The result is an adjusted row number that begins at 1. The INDEX function is simply one way get the first cell in a given range:

```
ROW(INDEX(data,1,1) // first cell
```

This is for convenience only. The formula could be re-written like as:

```
=ROW()-ROW($E$5)+1
```

Once we have a current row number, we can compare the row number to the total rows in the data less n:

```
current_row > ROWS(data)-n
```

If this expression returns TRUE, the current row is one of the last n rows we are looking for.

### Last n rows in a table

If data is in an Excel table, the formula can be adapted like this:

```
=ROW()-@ROW(Table1)+1>ROWS(Table1)-n
```

The logic is exactly the same, but we use a slightly different approach to get the first cell in the table:

```
@ROW(Table1)
```

You can think of the @ character as indicating "single":

```
=ROW(Table1) // returns {5;6;7;8;9;10;11;12;13;14;15}
=@ROW(Table1) // returns {5}
```

As before, the table formula returns TRUE in "last n rows" and FALSE in others.

### Last row only

To test for the last row only, you can use a slightly simplified version of the formula:

```
=ROW()-ROW(rng.first)+1=ROWS(rng)
```