[英]Excel: how to count combinations of cells over multiple columns?
突出顯示您的整個並插入 - 表格
在表格功能區中,將表格名稱更改為“InputTable”
在“數據”功能區的“獲取和轉換”部分中,單擊“從表” 。 這將調出 PowerQuery window。在 PowerQuery window 中:
創建一個新查詢(單擊主頁 - 管理 - 參考...或主頁 - 新來源 - 其他來源 - 空白查詢...這並不重要,我們只想創建一個新查詢,我們將無論如何在接下來的步驟中替換它的內容)
將(右側欄)中的名稱更改為“ffTableForDay”
單擊主頁 - 高級編輯器
插入以下代碼:
// Called "ffTable*" because it's a Function that returns a Function that returns a Table.
// Returns a function specific to a table that takes a day.
// Returned function takes a day and returns a table of meals for that day.
(table as table) as function => (day as text) as table =>
let
#"Type Column Name" = day & "_type",
#"Food Column Name" = day & "_Food",
#"Removed Other Columns" = Table.SelectColumns(table,{"ID", #"Type Column Name", #"Food Column Name"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{#"Type Column Name", "Type"}, {#"Food Column Name", "Food"}}),
#"Removed Blank Rows" = Table.SelectRows(#"Renamed Columns", each [Type] <> null and [Type] <> "" and [Food] <> null and [Food] <> ""),
#"Add Day" = Table.AddColumn(#"Removed Blank Rows", "Day", each day, type text)
in
#"Add Day"
創建新查詢
將查詢名稱更改為“Meals”
單擊主頁 - 高級編輯器
插入以下代碼:
let Source = InputTable, Days = {"Monday", "Tuesday", "Wednesday"}, #"Function Per Day" = ffTableForDay(Source), // get list of tables per call to ffTableForDay(InputTable)(day) #"Table Per Day" = List.Transform(Days, #"Function Per Day"), Result = Table.Combine(#"Table Per Day") in Result
創建新查詢
將查詢名稱更改為“ComboCount”
單擊主頁 - 高級編輯器
插入以下代碼:
let Source = Meals, // Created by clicking **Transform - Group By** and then, in the dialog box, clicking advanced and grouping by Food and Type #"Grouped Rows" = Table.Group(Source, {"Type", "Food"}, {{"Count", each Table.RowCount(_), type number}}) in #"Grouped Rows"
單擊主頁 - 關閉並加載
如果您的查詢選項設置為將查詢加載到工作簿(默認),然后刪除“膳食”選項卡,如果您願意的話。 如果您的查詢選項默認情況下不將查詢加載到工作簿,則右鍵單擊側欄中的“ComboCount”查詢,然后單擊“加載到...”
一旦我們讓“Meals”查詢工作,而不是創建一個“ComboCount”查詢,我們可以有
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.