Forum Discussion

Poisedon's avatar
Poisedon
Frequent Visitor
7 years ago
Solved

Set duplicate rows to 0 (NOT DELETE)

Hi all, In query editor i have a table like this Namefile        Value             a.xml              12  a.xml              12  a.xml              12  b.xml               8  c.xml            ...
  • Stachu's avatar
    Stachu
    7 years ago

    language version should not have any impact

     

    this is the easiest way to do it

    1) right click your original query, click Reference

    2) go to the newly created query, go to Advanced Editor
    3) remove last 2 rows

    4) add "," to the last row in the code

    5) paste this code below the existing one

        #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
        #"Grouped Rows" = Table.Group(#"Added Index", {"Namefile", "Value"}, {{"Index", each List.Min([Index]), type number}}),
        #"Merged Queries" = Table.NestedJoin(#"Added Index",{"Namefile", "Index"},#"Grouped Rows",{"Namefile", "Index"},"Grouped Rows",JoinKind.LeftOuter),
        #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Value"}, {"NewValue"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Grouped Rows",{"Index"}),
        #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Namefile", Order.Ascending}})
    in
        #"Sorted Rows"

    what happends conceptually is following:
    1) add index to table

    2) group by Filename and Value with Index aggergated as MIN
    3) reference the original query and merge with the grouped one on all 3 columns (this will require changing the code in the formula bar, as it is referencing step within same query)
    4) expand the value column

    5) remove index

    6) sort by filename