[英]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.