我有一个发票摘要和报告电子表格,并尝试为每个客户创建一个动态摘要(客户数量可以更改),其中每个客户列出每张发票,发票列表后列出每个客户的总和。最初,我这样做是为了首先列出每个客户的发票清单,然后在最后列出所有总计。这样做是为了简化事情。但是,我想显示每个客户的发票列表,其总数就在各自的列表之后,而不是全部放在最后。
即
List of invoices for client 1
List of invoices for client 2
Totals for client 1
Totals for client 2
Grand totals for all clients
与
Client 1
List of invoices for client 1
Totals for client 1
Client 2
List of invoices for client 2
Totals for client 2
Grand totals for all clients summarized
不幸的是,我知道如何将其显示为第一个示例的唯一方法将导致不存在的客户端出现许多空行。
客户名单被拉入:
=sort(UNIQUE(E6:E),1,true)
这个独特的公式是从另一个动态查询中提取客户名称,因此客户数量可能会发生变化。因此,下面我的查询公式中的摘要每行都有一个数组(作为示例,总共显示 4 个数组,可能会更高)。
查询数据,其中Data!N7:N16是由上述唯一公式得出的范围:
={query(Data!A5:I5,"select A,B,C,D,' ',F,G,H,I label ' ' ''");
IF(Data!N7<>"",
{{Data!N7,"","","","","","","",""};query(Data!A6:Y,"select A,B,C,D,' ',F,G,H,I where A is not null and E='"&Data!N7&"' label ' ' ''");query(Data!J6:Y,"select V,W,X,Y,O,J,K,L,M where N='"&Data!N7&"'");{"___________________________________________________________________________________________________________________________________________","","","","","","","",""}},
{"","","","","","","","",""});
IF(Data!N8<>"",
{{Data!N8,"","","","","","","",""};query(Data!A6:Y,"select A,B,C,D,' ',F,G,H,I where A is not null and E='"&Data!N8&"' label ' ' ''");query(Data!J6:Y,"select V,W,X,Y,O,J,K,L,M where N='"&Data!N8&"'");{"___________________________________________________________________________________________________________________________________________","","","","","","","",""}},
{"","","","","","","","",""});
IF(Data!N9<>"",
{{Data!N9,"","","","","","","",""};query(Data!A6:Y,"select A,B,C,D,' ',F,G,H,I where A is not null and E='"&Data!N9&"' label ' ' ''");query(Data!J6:Y,"select V,W,X,Y,O,J,K,L,M where N='"&Data!N9&"'");{"___________________________________________________________________________________________________________________________________________","","","","","","","",""}},
{"","","","","","","","",""});
IF(Data!N10<>"",
{{Data!N10,"","","","","","","",""};query(Data!A6:Y,"select A,B,C,D,' ',F,G,H,I where A is not null and E='"&Data!N10&"' label ' ' ''");query(Data!J6:Y,"select V,W,X,Y,O,J,K,L,M where N='"&Data!N10&"'");{"___________________________________________________________________________________________________________________________________________","","","","","","","",""}},
{"","","","","","","","",""});
{"","","","",Data!O6,Data!J6,Data!K6,Data!L6,Data!M6}}
结果是:
Client 1
List of invoices for client 1
Totals for client 1
Client 2
List of invoices for client 2
Totals for client 2
BLANK LINE SINCE N9 IS BLANK
BLANK LINE SINCE N10 IS BLANK
Grand totals for all clients summarized
如果唯一客户端的范围内不存在客户端,是否有更好的方法来完成此操作而无需这些空行?
我在这里使用一些公式创建了一个示例电子表格 https://docs.google.com/spreadsheets/d/1T9QkPGLzBMYd7lLy5EWd7ar_z4j97wweIZ6LJoBd-AU/edit?usp=sharing
尝试这样:
=REDUCE({"","","","","","","","",""}, N7:N8, LAMBDA(a, x, {a; {{{x,"","","","","","","",""};
query(Data!A6:Y,"select A,B,C,D,' ',F,G,H,I where A is not null and E='"&x&"' label ' ' ''");
query(Data!J6:Y,"select V,W,X,Y,O,J,K,L,M where N='"&x&"'");
{"___________________________________________________________________________________________________________________________________________","","","","","","","",""}}} }))