Google-sheets – Sheets ArrayFormula with SUMIF

google sheetsgoogle-sheets-arrayformulagoogle-sheets-arrays

In a 'Records' sheet I have columns of timestamp, a duration, and a category (i.e. 13 minutes of 'B' was done at 18/01/2021 00:00).

Records data

In the 'Analysis' sheet I have a field where the Type can be defined and then using Filter the matching rows are shown and can be worked with to create a 'Sum since' tally.

Analysis sheet

I am failing to write a formula for a single cell that will produce the array in the D column in Analysis. I can do this just fine assuming there is no 'Type' by using Arrayformula and Sumif, but it seems that Sumifs cannot be used with array formula, and query cannot be used with duration data.

Can anyone give me any pointers or better yet a working formula? The correct answer would slot into a larger formula I already have for a moving weighted average.

EDIT link to test sheet:
https://docs.google.com/spreadsheets/d/1-iPODUKQB4qRv2HNV4dZ-UwKkChzuKySu7YWEF0NJHQ/edit?usp=sharing

Best Answer

I added a new sheet ("Erik Help") with the following array formula in D2:

=ArrayFormula(IF(B2:B="",,SUMIF(IF(ROW(B2:B),ROW(B2:B)),">="&ROW(B2:B),C2:C)))

The initial IF(B2:B="",, just leaves cells blank if the corresponding cell from Column B of that row is also blank.

The opening IF(ROW(B2:B),ROW(B2:B)) of the SUMIF creates an array of all row numbers from B2:B, which can then be matched for each row against the condition to only include those that are greater than or equal to the current row (with durations in C2:C being summed accordingly).