Search code examples
powerbipowerquerypowerpivot

How can I get the latest date from a selection of dates in Power Query?


Could you please tell me how I can get the max date from a column that have dates like this:

Columns (formatted as text):

01/11/2020, 10/11/2020

Desired output:

10/11/2020

this code shows null:

#"Added Custom9" = Table.AddColumn(#"Added Custom8", "REAL_DATE_3", each  let dates =#"Added Custom8"[DATE_REAL_2] in [min = List.Min(dates), max = List.Max(dates)]),
expanded1 = Table.ExpandRecordColumn(#"Added Custom9", "REAL_DATE_3", {"min", "max"})

Solution

  • You can try this below code in Power Query Editor. Go to Advanced Editor to your respected table and incorporate this below code-

    let your column name: date_list

    let
        //--your existing steps,
        split = Table.AddColumn(#"previous_step_name", "datesToCheck", each List.Transform(Text.Split([date_list], ", "), each Date.FromText(_, "en-US")), type list),
        minAndMax = Table.AddColumn(split, "toExpand", each [max = List.Max([datesToCheck])], type record),
        expanded = Table.ExpandRecordColumn(minAndMax, "toExpand", {"max"})
    in
        expanded
    

    Here is the output my case-

    enter image description here