I can't get the last number that is not 0 from a selected area of columns.
I can't get the last number that is not =0 from E22:E52.
The columns are currency typed are both positive and negative numbers.
I can't get the last number that is not 0 from a selected area of columns.
I can't get the last number that is not =0 from E22:E52.
The columns are currency typed are both positive and negative numbers.
r
Source Range
n
ISNUMBER() <> 0
n
not equal to zero from the range r
n
which is calculated from a COUNT of all the rows in n
.=LET(r,E22:E52,
n,FILTER(r,ISNUMBER(r)*(r<>0)),
INDEX(n,COUNT(n)))
=INDEX(FILTER(E22:E52,ISNUMBER(E22:E52)*(E22:E52<>0)),
COUNT(FILTER(E22:E52,ISNUMBER(E22:E52)*(E22:E52<>0))))
The FILTER function in the formulas above won't return strings because one of its conditions uses ISNUMBER.
To accept strings that match number formats, A18
in my example images, those strings must first be coerced to numbers.
r
inside an ARRAYFORMULA with the VALUE function, or using any math operation that would 'not' change the value of a number. For example,
VALUE(r), r+0, r×1, r÷1, r×(½+½)
, etc.#VALUE!
errors (values that could not be coerced to numbers)FILTER({0;1;1/0;2},{0;1;1/0;2}<>0)={1;2}
FILTER({0;1;1/0;2},{0;1;1/0;2}=0)={0}
FILTER({0;1;1/0;2},NOT(ISERROR({0;1;1/0;2}))={0;1;2}
FILTER({0;1;1/0;2},ISERROR({0;1;1/0;2})={#DIV/0!}
=LET(r,ARRAYFORMULA(E22:E52*1),
n,FILTER(r,r<>0),INDEX(n,ROWS(n)))
# or
=LET(r,ARRAYFORMULA(VALUE(E22:E52)),
n,FILTER(r,r<>0),INDEX(n,COUNT(n)))
If there are NEVER any values in your data range that are text strings then you can simplify the formula by removing the ISNUMBER check
=LET(r,E22:E52, n,FILTER(r,r<>0),
INDEX(n,COUNT(n)))
# or
=INDEX(FILTER(E22:E52,E22:E52<>0),
COUNT(FILTER(E22:E52,E22:E52<>0)))
You could also try:
=LET(r,E22:E52,INDEX(r,MATCH(,ROW(r)*(r=0))))
Or:
=CHOOSEROWS(FILTER(E22:E52,E22:E52),-1)
The first formula uses MATCH
with an approximate lookup to find the relative position of the last row that doesn't respect the condition E22:E52=0
and then uses INDEX
to return the corresponding value.
The second formula filters out all the non zero values in E22:E52 and then uses CHOOSEROWS(...,-1)
to return the last one.
One of these will work (depending on your locale)
=INDEX(FILTER(E22:E52;E22:E52<>0);
COUNT(FILTER(E22:E52;E22:E52<>0)))
OR
=INDEX(FILTER(E22:E52,E22:E52<>0),
COUNT(FILTER(E22:E52,E22:E52<>0)))
Notice the ;
turning to ,