对于 powerquery,这是我的版本,假设您希望在 Status Key = 6 之后开始将计数加一。这可能更容易理解
添加索引
使用公式添加自定义列
= if [Status Key]=6 then [Index] else null
右键单击该自定义列并填写
单击选择产品 ID 和新的自定义列,然后选择分组依据。使用您想要的任何名称并操作所有行
添加另一个索引
扩展组创建的数据列以提取数据和状态键字段
删除多余的列
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Status Key]=6 then [Index] else null),
#"Filled Up" = Table.FillUp(#"Added Custom",{"Custom"}),
#"Grouped Rows" = Table.Group(#"Filled Up", {"Product ID", "Custom"}, {{"data", each _, type table}}),
#"Added Index1" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1),
#"Expanded data" = Table.ExpandTableColumn(#"Added Index1", "data", {"Date", "Status Key"}, {"Date", "Status Key"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded data",{"Custom"})
in #"Removed Columns"