I would be careful deleting rows from within a formula column. Every time the formula is re-evaluated, it will chop off the last row. However you can create a logical condition for the last row in a column formula using something like this:
If( Row() == N Row(Current Data Table()), do this, do that);
For your situation, I would run a separate script, not as in a formula column, to cut off the last row so you don't leave that code as a permanent feature of your resulting data table. In that case, the script would pretty much look like what you have.
-- Cameron Willden