有没有办法使 google 查询对多列求和可扩展?

Is there a way to make a google query sum multiple columns scalable?

现在我使用下面的函数对下图中显示的每一列中的数量求和。有时我需要添加更多的列,我什至可能需要多达 50+ 但我不想有一个超长的查询公式。有没有办法压缩它并将其编写为可扩展到我需要的列数?

函数:=ARRAYFORMULA(IF(ISBLANK(AN4:AN), "", TRANSPOSE(QUERY({VALUE(L4:AM)}, "SELECT sum(Col1), sum(Col2), sum(Col3), sum(Col4), sum(Col5), sum(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), sum(Col16), sum(Col17), sum(Col18), sum(Col19), sum(Col20), sum(Col21), sum(Col22), sum(Col23), sum(Col24), sum(Col25), sum(Col26), sum(Col27), sum(Col28) LABEL sum(Col1) '', sum(Col2) '', sum(Col3) '', sum(Col4) '', sum(Col5) '', sum(Col6) '', sum(Col7) '', sum(Col8) '', sum(Col9) '', sum(Col10) '', sum(Col11) '', sum(Col12) '', sum(Col13) '', sum(Col14) '', sum(Col15) '', sum(Col16) '', sum(Col17) '', sum(Col18) '', sum(Col19) '', sum(Col20) '', sum(Col21) '', sum(Col22) '', sum(Col23) '', sum(Col24) '', sum(Col25) '', sum(Col26) '', sum(Col27) '', sum(Col28) ''"))))

下图是用函数选择的单元格和输出。您可以看到它对列求和的范围。

是:

=INDEX(IF(AN4:AN="",,FLATTEN(QUERY(QUERY({VALUE(INDIRECT("L4:"&ROWS(L4:L)))}, 
 "select "&JOIN(",", " sum(Col"&SEQUENCE(30)&")")), "offset 1", ))))

要添加更多列,请将 30 更改为其他内容

循环依赖来自INDIRECT("L4:"&ROWS(L4:L))

您可以顺其自然并启用迭代

或使用类似的东西:

=INDEX(IF(AN4:AN="",,FLATTEN(QUERY(QUERY({VALUE(
 INDIRECT("L4:"&ADDRESS(ROWS(L4:L), COLUMN()-1, 4)))}, 
 "select "&JOIN(",", " sum(Col"&SEQUENCE(30)&")")), "offset 1", ))))