Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

PowerBI - max record with min date

Hi
I have the table attached and I want to have the output table attached.
Power BI has to get the last owned vehicle by person and then get when it was owned.

  • Hi

    let
    Source = YourSource,
    FillDown = Table.FillDown(Source,{"Name"}),
    Type = Table.TransformColumnTypes(FillDown,{{"Date owned", type date}}),
    Group = Table.Group(
    Type,
    {"Name", "Own"},
    {{"Max", each List.Max([Date owned]), type nullable date},
    {"Since", each List.Min([Date owned]), type nullable date}},
    GroupKind.Local),
    Sort = Table.Sort(Group,{{"Max", Order.Descending}}),
    Distinct = Table.Distinct(Sort, {"Name"})
    in
    Distinct

     

     

    Stéphane

1 Reply

  • Hi

    let
    Source = YourSource,
    FillDown = Table.FillDown(Source,{"Name"}),
    Type = Table.TransformColumnTypes(FillDown,{{"Date owned", type date}}),
    Group = Table.Group(
    Type,
    {"Name", "Own"},
    {{"Max", each List.Max([Date owned]), type nullable date},
    {"Since", each List.Min([Date owned]), type nullable date}},
    GroupKind.Local),
    Sort = Table.Sort(Group,{{"Max", Order.Descending}}),
    Distinct = Table.Distinct(Sort, {"Name"})
    in
    Distinct

     

     

    Stéphane