根据 MA​​TCH 标准对 Cell 进行分组和求和

Grouping and summing Cells based on MATCH criteria

例如,我在 B3:F20 中创建了一小组数据,其中包含组件、类型和计数列表等。我为 B24:B25 分配了一个名称“TypeP”。

我的目标是根据类型对组件进行分组,并从输入 B3:F20 中求和它们的数量。为了显示最终目标,我在 L3:N7 中手动添加了结果。在 L4 中,将具有相同类型 PA 的多个(这里是 2 个)组件 DEF 实例分组,并对计数求和。

我能够像 H3:J11 那样部分实现我的目标,其中数据是根据 TypeP 分组的,但我仍然应该能够对相似的类型进行分组。 我在 H3 中使用的公式是

=FILTER(INDEX(B3:F20;SEQUENCE(ROWS(B3:F20));{1});(ISNUMBER(匹配(C3:C20;TypeP;0) )=真))

如何才能达到L3:N7所示的效果?

L3: =UNIQUE(H3:I11)
N3: =SUMIFS($J:$J,$H:$H,L3,$I:$I,M3)

Select N3 并根据需要向下填写。

您也可以在 Power Query 中执行此操作

使用 Power Query

  • 将您的 TypeP 设为命名范围(或 Table)
  • Select 数据中的某个单元格 Table
  • Data => Get&Transform => from Table/Range
  • 当 PQ 编辑器打开时:Home => Advanced Editor
  • 记下第 2 行中的 Table 名称
  • 粘贴下面的 M 代码代替您看到的内容
  • 将第 2 行中的 Table 名称更改回最初生成的名称。
  • 阅读评论并探索 Applied Steps 以了解算法

M码

let

//Read main table
//Change table name in next line to real name of your table in the workbook
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

//set data types
    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"Component", type text}, {"Type", type text}, {"Count", Int64.Type}, 
        {"Others1", type text}, {"Others2", type any}}),

//read in the types to filter by from a "Named Range"
//  Range name is `TypeP` in the workbook
    typeP = Excel.CurrentWorkbook(){[Name="TypeP"]}[Content][Column1],

//Filter for the desired types
    filter = Table.SelectRows(#"Changed Type", each List.Contains(typeP,[Type])),

//Group by "component and type"
//Then sum the Count column
    #"Grouped Rows" = Table.Group(filter, {"Component", "Type"}, 
        {{"Count", each List.Sum([Count]), type nullable number}})
        
in
    #"Grouped Rows"