0

Follow-up to question 63893967:

How can I achieve the same result of...

giv[ing] a running count of Issues for a given day. In other words: the output should enumerate each Issue for a given date (returning blank if Issue is blank), and then start again at 1 for the first issue in a subsequent date

...but not use an ArrayFormula? i.e. I'd like to have a formula in each row, but the same values outputted as column J. The reason is that the iOS app crashes every time I open this spreadsheet on it now that I have the ArrayFormula in there.


Sample spreadsheet, looking on "Formula per row method" tab:

Screenshot

  • Column B contains the date
  • Column E contains the T-shirt size severity of each Issue
  • Column F contains a numerical translation of column E
  • Column G contains a binary output of whether there was an Issue in that row
  • Column I contains the ArrayFormula method:

=ArrayFormula(IF(F3:F="",,MMULT((ROW($B3:$B)>=TRANSPOSE(ROW($B3:$B))) * EXACT($B3:$B,TRANSPOSE($B3:$B))^1, ($G3:$G)^1)))

  • Column L reconciles the attempt in column J against the source of truth in column I

1 Answers1

2

The simplest thing to do would just be this:

=IF(F3="",,
    INDEX(
        MMULT(
            (ROW(B$3:B)>=TRANSPOSE(ROW(B$3:B))) * 
                EXACT(B$3:$B,TRANSPOSE(B$3:B)),
            G$3:G
        ),
        ROW(F3)-2
    )
)

...if you're ok with MMULTing at every row. I can see this getting slow for large data sets, though, assuming Sheets does in fact calculate this per every row. Of course, you can be more efficient if you memoize the MMULT result in another sheet and use that range.

Memoized MMULT()

We can create a new sheet (I called it "Memo") to memoize, or cache, the MMULT() so it only has to be calculated once.

=ArrayFormula(MMULT(
    (ROW('Formula per row method'!B3:B)>=TRANSPOSE(ROW('Formula per row method'!B3:B))) * 
        EXACT('Formula per row method'!B3:$B,TRANSPOSE('Formula per row method'!B3:B)),
    'Formula per row method'!G3:G
))

Then your original formula becomes:

=IF(F3="",,
    INDEX(
        Memo!A:A,
        ROW(F3)-2
    )
)

However, I'm not sure if this will work for you because you said ArrayFormula() wasn't working. It might just be breaking in your original use case, though, so it's worth a shot.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • This seems to work in the sample sheet, however it's breaking (and SUPER slow) in my real, 500-row-long file. I'm not fully getting on what you mean by "memorize the `MMULT` result"... can you give the exact formula you propose in the new tab, and the formula in the main tab? – SportyJordy Sep 18 '20 at 23:26
  • 1
    @SportyJordy Ok. I've added it, but it might not work after all due to ArrayFormula. If it doesn't, I'll rewrite my answer. – General Grievance Sep 19 '20 at 00:47
  • We have a winner! Thank you much as always. – SportyJordy Sep 19 '20 at 17:02