try:
=ARRAYFORMULA({IF(COUNTIFS(
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0),
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0), ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0)))), "<="&ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0)))))=1,
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col1", 0), ),
QUERY(QUERY(A:D, "select C,A,sum(D) where A !='' group by C,A label sum(D)''", 0), "select Col2,Col3", 0)})
Синтаксис EU:
=ARRAYFORMULA({IF(COUNTIFS(
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0);
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0); ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0)))); "<="&ROW(INDIRECT("F1:F"&COUNTA(
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0)))))=1;
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col1"; 0); )\
QUERY(QUERY(A:D; "select C,A,sum(D) where A !='' group by C,A label sum(D)''"; 0); "select Col2,Col3"; 0)})