【问题标题】:Excel: how to count combinations of cells over multiple columns?Excel:如何计算多列单元格的组合?
【发布时间】:2021-02-23 15:44:15
【问题描述】:

我的数据示例

如果我有如图所示的数据(实际数据具有相同的形式但要大得多),我将如何计算某个组合(例如组合晚餐 - 意大利面)在每个 ID 中出现的次数?理想情况下,我想在另一个选项卡中创建一个表格,显示每个 ID 的所有可能组合的计数。

提前致谢!

【问题讨论】:

    标签: excel combinations counting


    【解决方案1】:

    试试SUMPRODUCT:

    =SUMPRODUCT((I2=$A$2:$A$7)*(J2=$B$2:$F$7)*(K2=$C$2:$G$7))
    

    【讨论】:

      【解决方案2】:
      1. 突出显示您的整个和插入 - 表格

      2. 在表格功能区中,将表格名称更改为“InputTable”

      3. 数据功能区的Get & Transform部分,点击From Table。这将打开一个 PowerQuery 窗口。在 PowerQuery 窗口中:

      4. 创建一个新查询(点击 Home - Manage - Reference... 或 Home - New Sources - Other Sources - Blank Query... 它没有真的很重要,我们只想创建一个新查询,无论如何我们将在接下来的步骤中替换它的内容)

      5. 将(右侧)中的名称更改为“ffTableForDay”

      6. 点击首页 - 高级编辑器

      7. 插入以下代码:

      // 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"
      
      1. 创建一个新查询

      2. 将查询名称更改为“膳食”

      3. 点击首页 - 高级编辑器

      4. 插入以下代码:

        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
        
      5. 创建一个新查询

      6. 将查询名称更改为“ComboCount”

      7. 点击首页 - 高级编辑器

      8. 插入以下代码:

        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"
        
      9. 点击首页 - 关闭并加载

      10. 如果您的查询选项设置为将查询加载到工作簿(默认),那么如果您愿意,请删除“膳食”选项卡。如果您的查询选项默认情况下不将查询加载到工作簿,则右键单击侧栏中的“ComboCount”查询,然后单击“加载到...”

      或者

      一旦我们让“Meals”查询工作,我们就可以不用创建“ComboCount”查询了

      • 将膳食加载到工作簿并完成数据透视表,或者
      • 将 Meals 加载到数据模型并执行 Power Pivot。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-15
        • 1970-01-01
        相关资源
        最近更新 更多