Search code examples
excelgoogle-sheetsarray-formulasfrequencyflatten

Determine Size Of Array of Equal Items Excel


I have an array that looks like this

11100100110

essentially, an array of fixed size with each item being a 1 or 0 with the last item always equal to 0.

Consider each set of consecutive 1's to be a "bucket". I'd like a formula to determine the size of each bucket. So the output of this formula for the above sequence should be

312

as an array. Ideally this works in both excel and google sheets.

If you are interested this is the result of a list of stars and bars configurations where the 0's in my sequence represent bars and the 1's represent stars (the final value is a dummy 0 to make things easier to work with). I want the size of each non-empty bucket in a given configuration of stars and bars.

Thanks, in advance.


Solution

  • You could also use the standard method with Frequency which will work with Excel 365 and GS:

    =FILTER(FREQUENCY(IF(A1:A11=1,ROW(A1:A11)),IF(A1:A11=0,ROW(A1:A11))),FREQUENCY(IF(A1:A11=1,ROW(A1:A11)),IF(A1:A11=0,ROW(A1:A11))))
    

    enter image description here