Forum Discussion

Luke_Lee's avatar
Luke_Lee
Copper Contributor
Mar 25, 2021

[Power Query] How to find Max Value with condition in another column

Hi,   If any one know how to find max value with a conditional selection in another column? (Power Query only)   Example like below, try to find "Column 1 = B" + maximum value in column 2 ...
  • SergeiBaklan's avatar
    Mar 25, 2021

    Luke_Lee 

    In addition to Subodh_Tiwari_sktneer solution for column maximum here are couple of filtered maximums

    for external filter

    let
        filter = "A",
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(
            Source,
            {{"Column1", type text}, {"Column2", Int64.Type}}
        ),
        #"Added Custom" = Table.AddColumn(
            #"Changed Type",
            "maxExt",
            each
                [
                    max=Table.Group(
                        Source, {"Column1"},
                        {{"MaxFiltered", each List.Max([Column2])}}
                    ){[Column1=filter]}[MaxFiltered]
                ][max]
        )
    in
        #"Added Custom"

     

    max per group

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(
            Source,
            {{"Column1", type text}, {"Column2", Int64.Type}}
        ),
        #"Added Custom" = Table.AddColumn(
            #"Changed Type",
            "maxInt",
            each
                [
                    filter = [Column1],
                    max=Table.Group(
                        Source, {"Column1"},
                        {{"MaxFiltered", each List.Max([Column2])}}
                    ){[Column1=filter]}[MaxFiltered]
                ][max]
        )
    in
        #"Added Custom"

Resources