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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Maximum value in a column using Power Query

Hi There,

 

Hope you are doing well.

 

I am trying to create one custom column in Power Query where i need to take the Maximum value in each row with respect to other column.

My sample data has two columns i.e., "VBELN" and "VBELV" and my requirement is to create a custom column where i want Maximum values (VBELV) in each row with respect to "VBELN" column. and it should be using M query not DAX.

In Excel we can use Maxifs function which i want to replicate in M query . Please see below data set and solution in Excel which i am looking to replicate in M Query .

 

Capture.JPG

 

 

Capture.JPG

Request you to please help .

 

Thanks,

Ashish

6 REPLIES 6
slorin
Super User
Super User

Hi

Just group with max and [VBLEV] then expand

 

let
Source = YourSource,
Group = Table.Group(Source, {"VBELN"},
{{"VBELV", each [VBELV]},
{"Max", each List.Max([VBELV]), type number}}),
Expand = Table.ExpandListColumn(Group, "VBELV")
in
Expand

 

Stéphane

PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download example PBIX file

 

You can do this a couple of ways but both require doing a join of tables, or joining the query with itself.  In my example file I've duplicated the query and joined the 2 queries (tables).

 

The approach is to group the VBELN column on the max value in the VBELV column.  Then join the result with the original table.  This is the result

 

jquer.png

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi @PhilipTreacy

Thank you for your response.

I have tried the above step but i am not getting Max  value from "VBELN" . Also when i am getting Max value these  records are appearing 4 times .

I  need maximum value of "VBELN" with Respect to "VBELN" and in the output it should appear only one record /row with rest other columns

Please see below Excel what i am expecting now :

Capture.JPG

 

 

 

Capture.JPG

 

 

Request you to please help .

 

Thanks ,

Ashish

Hi,

Group by VBELN , use Table.Max function on VBELV column

then expand Record

 

let
Source = YourSource,
Group = Table.Group(Source, {"VBELN"}, {{"Data", each Table.Max(_, {"VBELV"}), type record}}),
Expand = Table.ExpandRecordColumn(Group, "Data", List.Difference(Table.ColumnNames(Source),{"VBELN"}), List.Difference(Table.ColumnNames(Source),{"VBELN"}))
in
Expand

 

Stéphane

Hi @Anonymous 

 

I'm confused.  My code does give you the max value of VBELV with respect to VBELN.

 

If you just want 1 row for each value of VBELN, just remove duplicates on the VBELN column.

 

If I'm not understanding please try explaining again perhaps with an image showing the final result you want.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi Phil,

 

I got the solution :

 

ashc_cool10_0-1687163146396.pngashc_cool10_1-1687163183693.png

I was doing one thing wrong in Group by I was taking that column aslo for which i need Max . SO i removed that column and took others and did the MAX of VBELN and go the result.

Thank you so much for your quick response though .

 

Regards,

Ashish

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.