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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Merleau
Helper II
Helper II

Remove rows based on second key in another column

Hello,

I need help filtering out data in a large dataset.

I have a table that looks like this:

Column1

Column2

 Value1

 Value2

 Value3

35

XY-23

  Prod1

  A

 1231

35

XY-23

  Prod2

  C

 1232

35

XY-23

  Prod3

  B

 1233

36

XY-23

  Prod1

  B

 1234

36

XY-23

  Prod3

  B

 1235

36

XY-23

  Prod4

  Y

  20

36

XY-23

  Prod5

  H

  30

40

XY-100

  Prod1

  U

  10

40

XY-100

  Prod9

 

  1

25

XY-100

  Prod2

  C

  1236

25

XY-100

  Prod9

  B

  1237

 

I want to group by Column2, then sort all records in Column1 and keep only the ones with the highest value in Column1.

 

Expected result should be:

 

Column1

 Column2

  Value1

  Value2

  Value3

36

XY-23

  Prod1

  B

 1234

36

XY-23

  Prod3

  B

  1235

36

XY-23

  Prod4

  Y

  20

36

XY-23

  Prod5

  H

  30

40

XY-100

  Prod1

  U

  10

40

XY-100

  Prod9

 

  1

 

Can somebody pls help?

Thanks.

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

    gr = Table.Group(
        your_tbl, 
        "Column2", 
        {"x", (x) => 
            [a = List.Max(x[Column1]), 
            b = Table.SelectRows(x, (w) => w[Column1] = a)][b]}),
    z = Table.Combine(gr[x])

View solution in original post

3 REPLIES 3
Merleau
Helper II
Helper II

Many thanks to @AlienSx  and @PhilipTreacy  for your quick responses. Both solutions work perfectly.

AlienSx
Super User
Super User

    gr = Table.Group(
        your_tbl, 
        "Column2", 
        {"x", (x) => 
            [a = List.Max(x[Column1]), 
            b = Table.SelectRows(x, (w) => w[Column1] = a)][b]}),
    z = Table.Combine(gr[x])
PhilipTreacy
Super User
Super User

Hi @Merleau 

 

Download example PBIX file

 

Duplicate your starting table. 

 

With this table group by Column2 and choose Max of Column1 as the aggregation.  name the new column Column1

 

grpcol.png

 

Which gives

 

grpcol2.png

 

Select this new table and then Merge it with the original table, using Column1 as the matching column

 

grpcol3.png

 

Giving this

 

grpcol4.png

 

Click the double headed arrow in the column header to expand the tables, only choosing the value columns

 

grpcol5.png

 

Rearrange columns as needed

 

grpcol6.png

 

Please check my PBIX file (linked above) for this example data and queries.

 

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!


Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.