Forum Discussion

diablo9083's avatar
diablo9083
Frequent Visitor
1 year ago
Solved

M - Created Column to Tag Duplicates

I'm trying to use M to create a column that will tell me when values in another column are duplicated. My end result is I want to use this column to filter out data in a subsequent step.   Prior to...
  • Bibiano_Geraldo's avatar
    Bibiano_Geraldo
    1 year ago

    Hi diablo9083 ,

    Please consider to use this query, if not works, please provide the sample data and the desired output. make sure that the data can be pasted in excel:

    let
        // Step 1: Reference your existing Sales table
        #"Added Index" = Sales,  // Replace this with your starting table if needed
    
        // Step 2: Extract the Completed Order ID column as a list
        CompletedOrderList = Table.Column(Sales, "Completed Order ID"),
    
        // Step 3: Add a custom column to tag duplicates
        #"Added Custom" = Table.AddColumn(#"Added Index", "Duplicated", each 
            if List.Count(List.Select(CompletedOrderList, (x) => x = [Completed Order ID])) > 1 
            then "Duplicated" 
            else null),
    
        // Step 4: Filter rows to remove duplicates
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Duplicated] = null)
    in
        #"Filtered Rows"