Forum Discussion

imranamikhan's avatar
imranamikhan
Helper V
3 years ago
Solved

Get second highest value per group in Power Query

Hi everyone,   I have a table with a list of projects. Each project is duplicated per the number of reporting periods. The reporting period is identified by a number column.     I am curre...
  • Ashish_Mathur's avatar
    3 years ago

    Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Reporting Period", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Project Name"}, {{"2nd latest reporting period", each try List.Sort([Reporting Period],Order.Descending){1} otherwise 1, type nullable number}})
    in
        #"Grouped Rows"

    Hope this helps.