I have a sheet with several columns. The rows could go up to the 10s of thousands. Some of the rows are subtotals from the rows below. I have an automated index that works like below:
i
i.i
i.i.i
i.i.j
j
j.i
j.j
i is a subtotal of all i.x items, while i.i is a subtotal of all i.i.x items and so on.
The lowerest indexes are always items, which have their own value.
Problem is, as the sheet is filled and rows are added, it goes slower to the point of becoming unusable.
link to the desensitized sheet *open in excel, there are named formulas that won't open on google sheets.
What consumes processing power is the subtotals. So far, I have used both: sumifs(), sum(filter()), sumproduct(), sum({array}*{array}), to automatically calculate de subtotals, and the performance is bad on all options.
I realize that using a regular subtotal() would cut processing consumption, but, in the other hand, when new rows are added in the middle of the sheet, it requires a lot of adjustments to fix the ranges that need to be summed. Oftenly, my team make some mistake into adjusting the ranges, resulting in wrong subtotals and having a hard time finding it later, consuming a lot of worktime
Pivot table is not an option, nor the group subtotals, since I need to follow the structure and formatting of the original sheet.
Do you guys have any idea on how to do this in a better way?
CodePudding user response:
You don't need alternative functions; you simply need to reduce the number of redundant calculations:
looking at row 7, the filters in cells O7:R7
are all filtering on the same criteria (which are calculated, afresh, for each filter), so instead of 4 separate (but related, since they all use the same criteria) filters, you could simply write the formula below
=LET(net,FILTER(O$2:R$465,(LEFT($I$2:$I$465,LEN($I7) 1)=$I7&".")*($J$2:$J$465<>0)*ISNUMBER(VALUE(RIGHT($I$2:$I$465,1))),0),MMULT(SEQUENCE(1,ROWS(net),1,0),net))
(i.e. apply a single filter, once, to the 4-column range, and generate a sum for each column)
in cell O7
, and see that it generates the same totals
similarly (still on row 7), all of the filters in cells X7:GI7
are also using the same criteria (i.e. the same criteria being calculated 168 times(!)), such that you could write the formula below
=LET(net,N(FILTER(X$2:GI$465,(LEFT($I$2:$I$465,LEN($I7) 1)=$I7&".")*($J$2:$J$465<>0),0)),MMULT(SEQUENCE(1,ROWS(net),1,0),net))
(again, a single filter, once, of a multi-column range, calculating a sum for each column)
in cell X7
and eliminate the redundant calculations from X7:GI7
Making these updates will result in 170 fewer uses of the FILTER()
function, per sub-total row (together with no-longer duplicated criteria calculations) so I anticipate that this will improve performance to some extent.