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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
U156531
Post Patron
Post Patron

Eliminating duplicates rows in table

My table has the folowwing data. I only want the row where Col2 has the max value. Is there a method to do this at the Table view level? If not what would be an alternative mehtod?

 

Col1    Col2

1           1

1           2

1           3

1 ACCEPTED SOLUTION

Hi @U156531 ,

 

Please try this code in power query advanced editor,

let

    Source = #table(
        {"Col1", "Col2"}, 
        {
            {1, 1},
            {1, 2},
            {1, 3},
            {2, 2},
            {2, 3},
            {2, 4},
            {3, 5},
            {3, 4},
            {3, 3}
        }
    ),
   NewTable = Table.Group(
        Source, 
        {"Col1"}, 
        {{"Col2", each List.Max([Col2])}}
    )
in
    NewTable

vbofengmsft_0-1727072128529.png

vbofengmsft_1-1727072142484.png

 

Best Regards,

Bof

View solution in original post

11 REPLIES 11
parry2k
Super User
Super User

@U156531 keep in mind, PQ is case-sensitive, make sure the name of the column is the same case. Or delete this step and manually rename the columns.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@U156531 it should be this:

 

let
Source = Oracle.Database("aaaaaa", [HierarchicalNavigation=true]),
ASOWNER = Source{[Schema="aaaaa"]}[Data],
TIDDVCU = ASOWNER{[Name="TIDDVCU"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(TIDDVCU,{{"design_number", Int64.Type}, {"design_version", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"design_number"}, {{"Count", each Table.Max(_,"design_version")}}),
#"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"design_number"}, {"design_version"})
in
#"Expanded Count"


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I double checked that design_number is the correct column name.

 

U156531_0-1726844360274.png

 

Ashish_Mathur
Super User
Super User

Hi,

This M code in Power Query works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", Int64.Type}, {"Col2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Col1"}, {{"Count", each Table.Max(_,"Col2")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Col2"}, {"Col2"})
in
    #"Expanded Count"

Hope this helps.

Ashish_Mathur_0-1726801214427.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I'm getting the following error. Can you tell me what I'm doing wrong?

U156531_0-1726839122916.png

 

let
Source = Oracle.Database("aaaaaa", [HierarchicalNavigation=true]),
ASOWNER = Source{[Schema="aaaaa"]}[Data],
TIDDVCU = ASOWNER{[Name="TIDDVCU"]}[Data],
#"Changed Type" = TIDDVCU.TransformColumnTypes(Source,{{"design_number", Int64.Type}, {"design_version", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"design_number"}, {{"Count", each Table.Max(_,"design_version")}}),
#"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"design_number"}, {"design_version"})
in
#"Expanded Count"

No, I cannot help by just looking at a screenshot.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-bofeng-msft
Community Support
Community Support

Hi @U156531 ,

 

Would you like to group the data by Col1, keeping only the row with the highest value in Col ?

 

Thanks for @dharmendars007's concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

 

1\My table(MyTable)

vbofengmsft_2-1726795181988.png

 

2\Create a new table 

NewTable = SUMMARIZE(MyTable,MyTable[Col1],"Col2",MAX(MyTable[Col2]))

vbofengmsft_1-1726795159093.png

 

Best Regards,

Bof

 

Bof, This seems to work. However my existing table is very large so I don't want to duplicate it. Is there a way I can use this summarize function in conjuction with my existing table?

Hi @U156531 ,

 

Please try this code in power query advanced editor,

let

    Source = #table(
        {"Col1", "Col2"}, 
        {
            {1, 1},
            {1, 2},
            {1, 3},
            {2, 2},
            {2, 3},
            {2, 4},
            {3, 5},
            {3, 4},
            {3, 3}
        }
    ),
   NewTable = Table.Group(
        Source, 
        {"Col1"}, 
        {{"Col2", each List.Max([Col2])}}
    )
in
    NewTable

vbofengmsft_0-1727072128529.png

vbofengmsft_1-1727072142484.png

 

Best Regards,

Bof

dharmendars007
Super User
Super User

Hello @U156531 , 

 

Please try the below code..

 

FilteredTable =
FILTER(YourTable, YourTable[Col2] = MAX(YourTable[Col2]))

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

dharmendars007, Where does this code get placed?

 

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors