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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mb0307
Responsive Resident
Responsive Resident

Power Query - max date by product

Hi,

 

I need help with PowerQuery - thanks in advance.

 

I have a table below:

mb0307_0-1614122238937.png

 

I need to create a Custom Column in PowerQuery showing Max Date per Product.  

 

Result in same table:

mb0307_0-1614163773641.png

 

 

Thanks.

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @mb0307 

To add a column like this, I would typically do a self-join (on the Product column in this case) and aggregate to get the max date.

 

Sample M code (last 2 steps are the important ones):

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUt9Q3MjAyVIrVwSFgjC5ggixgBNJiqA9EBIWM8QrFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", Int64.Type}, {"Date", type date}}),
    #"Merge with Self" = Table.NestedJoin(#"Changed Type", {"Product"}, #"Changed Type", {"Product"}, "JoinOnProduct", JoinKind.LeftOuter),
    #"Aggregate Max Date" = Table.AggregateTableColumn(#"Merge with Self", "JoinOnProduct", {{"Date", List.Max, "Max Date per Product", type date}})
in
    #"Aggregate Max Date"

 

Regards

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hi @mb0307 

To add a column like this, I would typically do a self-join (on the Product column in this case) and aggregate to get the max date.

 

Sample M code (last 2 steps are the important ones):

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUt9Q3MjAyVIrVwSFgjC5ggixgBNJiqA9EBIWM8QrFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", Int64.Type}, {"Date", type date}}),
    #"Merge with Self" = Table.NestedJoin(#"Changed Type", {"Product"}, #"Changed Type", {"Product"}, "JoinOnProduct", JoinKind.LeftOuter),
    #"Aggregate Max Date" = Table.AggregateTableColumn(#"Merge with Self", "JoinOnProduct", {{"Date", List.Max, "Max Date per Product", type date}})
in
    #"Aggregate Max Date"

 

Regards

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.