我面臨與動態陣列相關的問題。
我有以下格式的資料。

我想轉換成這種格式。


公式打開以在 Google 表格{中打開一個
所以基本上,我用相同數量的列的陣列來組織資料。第一個有部分
= { => To open the array.
"Fruits:",""; => This create a cell with "Fruits:" an empty cell.
QUERY(B5:D,"select C, D where B ='Fruits'"); => which is
already on an array of 2 columns.
{"Total:",SUMIF(B5:D,"Fruits",D5:D)}; => Creates the "Total" cell the sum
of values that has Fruits in column B.
"",""; => Which will create an empty row to separate the information
for the next set of arrays.
您對其他類別執行相同的模式。
} => to end the initial array.
您可以添加一個“
參考:
- 查詢功能
- 蘇米夫
- 陣列公式
uj5u.com熱心網友回復:
要在公式中構建沒有硬編碼類別名稱的結果表,請使用最近引入的 lambda 函式,如下所示:
={
lambda(
data, categories, headers, totalsHeader, blankRow, selectPrice,
reduce(
headers, query(unique(categories), "where Col1 is not null", 0),
lambda(
resultTable, filterKey,
{
resultTable;
lambda(
filterData,
{
filterData;
{ totalsHeader, query(filterData, selectPrice, 0) };
blankRow
}
)(filter(data, categories = filterKey))
}
)
)
)(
B5:D,
B5:B,
B4:D4,
{ "", "Total:" },
{ "", "", "" },
"select sum(Col3) label sum(Col3) '' "
);
{ "", "Grand Total:", sum(D5:D) }
}
請參閱{ 陣列運算式 }、filter()、query()、reduce()和lambda()。
該公式將在幾行上重復每個類別名稱。如果它們妨礙您,您可以使用條件格式自定義公式規則將它們隱藏起來。
uj5u.com熱心網友回復:
我建議您繼續閱讀:https ://stackoverflow.com/a/58042211/5632629
公式的第一部分輸出一個 4×3 單元格的網格
公式的第二部分輸出一個單元格
如果您想正確組合它,請使用:
={FILTER(A5:D11, B5:B11="Fruits");
{"","","Totals",SUM(FILTER(D5:D11, B5:B11="Fruits"))}}
或者:
={FILTER(B5:D11, B5:B11="Fruits");
{"","Totals",SUM(FILTER(D5:D11, B5:B11="Fruits"))}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/512906.html
下一篇:基于日期所需的Excel特定公式
