Search code examples
google-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-querycounting

Looking to count zero values from right to left until non-zero values appears


I have a large table of monthly values.
I am looking to count the zero values from right to left, stopping once a non-zero value occurs.
I want the last column to display these values.

| JAN | FEB | MAY | APR | MAY | JUN | Value I need |
Ben | 10 | 10 | 10 | 0 | 0 | 0 | =3 |
Tim | 0 | 0 | 10 | 10 | 10 | 0 | =1 |
Susan | 0 | 0 | 5 | 10 | 0 | 10 | =0 |
Frank | 10 | 0 | 0 | 10 | 10 | 10 | =0 |

Many thanks for any help!


Solution

  • I don't think you need anything very sophisticated - just find last column which is non-zero:

    =ArrayFormula(columns(B:G)-max(if(B2:G2>0,column(B:G)-column(A:A),0)))
    

    enter image description here