cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
BrunoAndrade182
New Member

Removing duplicates with MAX condition in powerquery

I need Help with powerquery editor: 

 

Hi guys,

I want to remove duplicate values of "PO IMPORTER" column but keeping only the MAx of colmun "LI APPROVAL DATE". 

I already done that in powerBI dax formula but is not working direclty in powerquery editor (because maybe it's M language).

 

 

BrunoAndrade182_0-1653926083765.png

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsrQwVNJRigJiY30TfSMDIwMgE0oZQpmGSrE60UqGRsZAvhNITN/QGKTUEJdSE1MzID8YiE30TYkw1AVsvSERKl3BZlrgVQnxUjhCJQF3uoPECdgOUekBNtMIpNIIv0pPiJl4PB8LAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"PO IMPORTER" = _t, Attribute = _t, #"LI APPROVAL DATE" = _t, Year = _t, Quarter = _t, YearMerged = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PO IMPORTER", Int64.Type}, {"Attribute", type text}, {"LI APPROVAL DATE", type date}, {"Year", Int64.Type}, {"Quarter", Int64.Type}, {"YearMerged", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"PO IMPORTER", Order.Ascending}, {"LI APPROVAL DATE", Order.Descending}}),
    BuffTbl = Table.Buffer(#"Sorted Rows"),
    #"Removed Duplicates" = Table.Distinct(BuffTbl, {"PO IMPORTER"})
in
    #"Removed Duplicates"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsrQwVNJRigJiY30TfSMDIwMgE0oZQpmGSrE60UqGRsZAvhNITN/QGKTUEJdSE1MzID8YiE30TYkw1AVsvSERKl3BZlrgVQnxUjhCJQF3uoPECdgOUekBNtMIpNIIv0pPiJl4PB8LAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"PO IMPORTER" = _t, Attribute = _t, #"LI APPROVAL DATE" = _t, Year = _t, Quarter = _t, YearMerged = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PO IMPORTER", Int64.Type}, {"Attribute", type text}, {"LI APPROVAL DATE", type date}, {"Year", Int64.Type}, {"Quarter", Int64.Type}, {"YearMerged", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"PO IMPORTER", Order.Ascending}, {"LI APPROVAL DATE", Order.Descending}}),
    BuffTbl = Table.Buffer(#"Sorted Rows"),
    #"Removed Duplicates" = Table.Distinct(BuffTbl, {"PO IMPORTER"})
in
    #"Removed Duplicates"

 

Thanks for the Help, this kind of language is new to me but it works well to my Query :). 

Tks a lot! 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors