Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
NanardPet
Regular Visitor

Max value from a column in Power Query Editor for each value in another column

Hi there,

 

I would like to select all the rows of a table for which, for each different record, the fiscal year corresponds to the last year of this record. Here is the expected result in Excel:

 

RecordFiscalYearMaxOfFiscalYearSelect
GE20162021FAUX
GE20172021FAUX
GE20182021FAUX
GE20192021FAUX
GE20202021FAUX
GE20212021VRAI
ADE20132020FAUX
ADE20142020FAUX
ADE20152020FAUX
ADE20162020FAUX
ADE20172020FAUX
ADE20182020FAUX
ADE20192020FAUX
ADE20202020VRAI

 

Many thanks in advance for a solution

 

Bernard

 

2 ACCEPTED SOLUTIONS
m_alireza
Solution Specialist
Solution Specialist

Hi @NanardPet 

You can achieve this through the group by function in Power Query. Copy and paste this in your advanced editor and amend as needed: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcndV0lEyMjA0U4rVQfDMUXgWKDxLZJ6RAQrPEMxzdIEqNUblmqByTVG5Zqhcc1SuBSrXEoULckUsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Record = _t, FiscalYear = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Record", type text}, {"FiscalYear", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Record"}, {{"MaxOfFiscalYear", each List.Max([FiscalYear]), type nullable number}, {"AllRows", each _, type table [Record=nullable text, FiscalYear=nullable number]}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"FiscalYear"}, {"FiscalYear"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded AllRows", "Select", each if [FiscalYear] = [MaxOfFiscalYear] then true else false)
in
    #"Added Conditional Column"


Sample output: 
maxfy.png

View solution in original post

NanardPet
Regular Visitor

Thanks a lot m_alireza : it works fine!

View solution in original post

2 REPLIES 2
NanardPet
Regular Visitor

Thanks a lot m_alireza : it works fine!

m_alireza
Solution Specialist
Solution Specialist

Hi @NanardPet 

You can achieve this through the group by function in Power Query. Copy and paste this in your advanced editor and amend as needed: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcndV0lEyMjA0U4rVQfDMUXgWKDxLZJ6RAQrPEMxzdIEqNUblmqByTVG5Zqhcc1SuBSrXEoULckUsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Record = _t, FiscalYear = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Record", type text}, {"FiscalYear", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Record"}, {{"MaxOfFiscalYear", each List.Max([FiscalYear]), type nullable number}, {"AllRows", each _, type table [Record=nullable text, FiscalYear=nullable number]}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"FiscalYear"}, {"FiscalYear"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded AllRows", "Select", each if [FiscalYear] = [MaxOfFiscalYear] then true else false)
in
    #"Added Conditional Column"


Sample output: 
maxfy.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.