Forum Discussion

oscargushiken's avatar
oscargushiken
Frequent Visitor
4 years ago
Solved

Eliminate duplicate values based on earliest date and filtered by another column

Dear forum,   I am attempting to issolate the distinct JOB_CODE values by the earliest date it appears in a row for each EMPLOYEE_ID.  I have a data table that records employee events, such has cha...
  • Ashish_Mathur's avatar
    4 years ago

    Hi,

    See if this M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATE", type datetime}, {"EMPLOYEE_ID", Int64.Type}, {"JOB_CODE", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"EMPLOYEE_ID","JOB_CODE"}, {{"All", each Table.Max(_,"DATE")}}),
        #"Expanded All" = Table.ExpandRecordColumn(#"Grouped Rows", "All", {"DATE"}, {"DATE"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded All",{{"DATE", type date}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"EMPLOYEE_ID", Order.Ascending}, {"DATE", Order.Descending}})
    in
        #"Sorted Rows"

    Hope this helps.