Power Query keep only max records

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a table with one column containing many duplicate values, and a second column with values. I want to filter my table so column 1 is all of the unique values corresponding with the max of column 2.

So I might have,

Col1, Col2
Yellow, 4
Yellow, 6
Red, 1
Red, 4
Blue, 2

I want my resulting table to be

Yellow, 6
Red, 4
Blue, 2

I've tried using a self-join, aggregating by max on Col2 and then keeping only the max values, but it's really slow. Are there any better approaches?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
When removing duplicates PQ will keep the first lines. So ordering by Col2 (1st) and Col1 (2nd) before removing duplicates should do the job.
But you have to wrap your sorting result into a Table.Buffer(...), as often the sorting will not be kept (especially if you load to the Data model).
 
Upvote 0
Hi
Let your table with columns (Col1, Col2) has a name - table1
Code:
maxOnly = Table.Group(table1, {"Col1"}, { {"Col2", each List.Max(_[Col2]), type number} }, GroupKind.Global)
Regards,
 
Upvote 0

Forum statistics

Threads
1,224,151
Messages
6,176,717
Members
452,740
Latest member
MrCY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top