在Power查询中删除重复项,而不删除整个行

时间:2019-11-08 17:49:25

标签: excel duplicates powerquery

enter image description here我需要删除多列中的重复项,而不要删除整行。我有多个列的查询,有6列我想从中删除重复项。列标题为:

“不可预测的订单” “预测订单” “预测和未预测” “未结订单” “能力” “事实”

我上一个应用的步骤是“ Reordered Columns2”。 M代码是什么?提前致谢。

我无法分组,因为每个“预测日期”都是给定的月份,并且与该月份对应的月份为“预测月份”。如果无法在不删除整行的情况下删除这些重复项,是否可以将重复项替换为null或将其留空?谢谢。

1 个答案:

答案 0 :(得分:0)

如果您要删除指定列中的所有重复项,而不管其余[产品,预测日期,预测月份,属性]列中的值是什么,请使用

#"Added Index" = Table.AddIndexColumn(#"Reordered Columns2", "Index", 0, 1),
#"Removed Other Columns" = Table.SelectColumns(#"Added Index",{"Product", "Forecast Date", "Month in Forecast", "Attribute", "Index"}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Other Columns", {"Index"}, "Attribute.1", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Added Index",{"Product", "Forecast Date", "Month in Forecast", "Attribute"}),
#"Unpivoted Other Columns2" = Table.UnpivotOtherColumns(#"Removed Columns", {"Index"}, "Attribute.1", "Value"),
#"Removed Duplicates" = Table.Distinct(#"Unpivoted Other Columns2", {"Attribute.1", "Value"}),
Combined = #"Unpivoted Other Columns" & #"Removed Duplicates",
#"Pivoted Column" = Table.Pivot(Combined, List.Distinct(Combined[Attribute.1]), "Attribute.1", "Value"),
#"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns1",{{"Forecast Date", type date}, {"Month in Forecast", type date}})
in #"Changed Type1"

如果您要根据[产品,预测日期,预测月份,属性]中的第一个分组,删除指定列中的所有重复项,请使用

#"Added Index" = Table.AddIndexColumn(#"Reordered Columns2", "Index", 0, 1),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Product", "Forecast Date", "Month in Forecast", "Attribute","Index"}, "Attribute.1", "Value"),
#"Removed Duplicates1" = Table.Distinct(#"Unpivoted Other Columns", {"Product", "Forecast Date", "Month in Forecast", "Attribute", "Attribute.1", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Removed Duplicates1", List.Distinct(#"Removed Duplicates1"[Attribute.1]), "Attribute.1", "Value", List.Sum),
#"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"Index", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"})
in #"Removed Columns"