Forum Discussion

ratercero's avatar
ratercero
Icon for Helper III rankHelper III
8 years ago

On Power Query Editor, how to filter rows with the earliest date each name aprears

Hello I merged 4 tables, that have duplicate values, I want to keep only the one that has the earliest date for each "Lote" (ignoring case), how can I fix this? The code I have removes duplicates but not in a defined order:

 

 

let
    Source1 = Table.AddColumn(PNC_TELA, "Source", each "PNC_TELA"),
    Source3 = Table.AddColumn(TONO_MALO, "Source", each "TONO_MALO"),
    #"Removed Other Columns" = Table.SelectColumns(Source3,{"Fecha de Ingreso", "Lote", "Defecto 1", "Disposición", "CatCausa", "Causa", "Comentarios", "Proceso Responsable", "Source"}),
    Source2 = Table.AddColumn(PNC_PARTES_CORTADAS, "Source", each "PNC_PARTES_CORTADAS"),
    Source4 = Table.AddColumn(VARIACION_TONO, "Source", each "VARIACION_TONO"),

SourceMerge = Table.Combine({#"Removed Other Columns",Source4, Source1, Source2}),
    #"Filtered Rows1" = Table.SelectRows(SourceMerge, each [Lote] <> null and [Lote] <> ""),
    #"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Fecha de Ingreso", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each true),
  #"Remove Duplicates" = Table.Distinct(#"Filtered Rows", { "Lote", Comparer.OrdinalIgnoreCase })
in
    #"Remove Duplicates"

Best Regards