仅将复杂的 arrayformula() 应用于数据集中具有特定值的行

Only apply complex arrayformula() to rows with certain value in dataset

我有一个非常复杂的公式(我的意思是这对我来说很复杂)Tom Sharpe helped me building to aggregate values and ordering them by months in a row(you can find the details in 但我认为你只需要最终的公式是:

=ArrayFormula(mmult(sequence(1,counta(A2:A),1,0), if((C2:index(C:C,counta(C:C))<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:index(D:D,counta(D:D))>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:index(E:E,counta(E:E)),0)))

这里是 result -> [J1:U1]

现在,我需要做的最后一步是能够按特定标签(示例中的 John 或 Jane)在不同的行上对数据进行分组,但按月维护 order/aggregate在行上。在这个例子中,这意味着一行只有 'John' 个数据,而下面的一行有 'Jane' 个值。

我很难理解如何调整公式来做到这一点。 我试过:

这些解决方案的问题在于它们在单独使用时可以正常工作,但我不知道如何将其嵌套在 Tom 帮助我的第一个 arrayformula() 中......因为我刚刚开始google 表查询。

我不一定真的需要完整的 formula/code,但可能只是指导或提示以形象化我解决这个问题的方式。

感谢所有可能做出贡献的人

事后看来,我可能会更好地使用查询来计算我之前答案的总和,而不是 Mm​​ult。

这使用与以前相同的方法创建一个二维数组,其中包含金额与日期(跨越)和个人(下降)。然后它使用 Textjoin 生成一个查询,以使用所需的列数按名称分组。

=ArrayFormula(query({A2:A,if((C2:C<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:D>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:E,0)},
"select Col1,sum(Col"&textjoin("),sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2))&") where Col1 is not null group by Col1"))

这是生成的查询

select 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) where Col1 is not null group by Col1

理想情况下应该有一个额外的部分说 label sum(Col2) '' 等来抑制 'Sum' headers.

=ArrayFormula(query({A2:A,if((C2:C<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:D>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:E,0)},
"select Col1,sum(Col"&textjoin("),sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2))&") where Col1 is not null group by Col1 label sum(Col" & textjoin(") '', sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2)) & ") ''"))