Search code examples
if-statementgoogle-sheetsmaxarray-formulas

Finding row number of last cell with value not equal to 0 in specific column


I have a Google Sheet calculating my monthly expenses. One of the columns contains sums of daily expenses. I want to calculate average expenses per day by dividing sum of all costs (up to current day) by number of days. So my idea is to get the row number of the last cell with value greater than 0.0. For example, let's say I have a column like:

8/16/2015   0.0
8/17/2015   0.0
8/18/2015   13.7
8/19/2015   0.0
8/20/2015   0.0
8/21/2015   0.0
8/22/2015   0.0
8/23/2015   82.2
8/24/2015   0.0
8/25/2015   0.0
8/26/2015   0.0
8/27/2015   0.0
8/28/2015   0.0

So the last cell with value greater than 0 is one in a row with date 8/23/2015. I want to get its row number or somehow extract 23 from the date.


Solution

  • If 8/16/2015 is in A1 please try:

    =ArrayFormula(max(if(B:B>0,A:A)))  
    

    If the formula is in C1 and you want just 23, try =day(C1)