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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
mike-germany
New Member

New Column with latest value

Hi, I have a table with 4 columns: Date, Item-Number, Item-Name, Sales. The Item-Name (of the same Item-Number) changes over time.
-> I want to add a column with Power Query M which adds the latest Item-Name for each row, as below. Thanks your help! Mike

 

sample-data.JPG

1 ACCEPTED SOLUTION

Hi @mike-germany , 

You could try below M code to see whether it works or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA31DdU0lEyNISSCn6JuakgtpFSrA5ciRmGEiMg2wRZiaERhhpjINsMRQ3IXCMjCInbJlQl2G1CVYPVJmNjYwiJ2yZUJdhtQlUDtSkWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, #"Item-Number" = _t, #"Item-Name" = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Item-Number", Int64.Type}, {"Item-Name", type text}, {"Sales", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Item-Number"}, {{"max", each List.Max([Date]), type date}, {"all", each _, type table [Date=date, #"Item-Number"=number, #"Item-Name"=text, Sales=number]}}),
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Date", "Item-Name", "Sales"}, {"Date", "Item-Name", "Sales"}),
    #"Added Custom" = Table.AddColumn(#"Expanded all", "Custom", each if [max]=[Date] then [#"Item-Name"] else null),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"Custom"}),
    #"Removed Columns" = Table.RemoveColumns(#"Filled Up",{"max"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
mike-germany
New Member

I could solve it with a reference table, group by funtion, and merge the tables again afterwards. However I'd still be interested if there isn't a more elegant solution within the original table.

Hi @mike-germany , 

You could try below M code to see whether it works or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA31DdU0lEyNISSCn6JuakgtpFSrA5ciRmGEiMg2wRZiaERhhpjINsMRQ3IXCMjCInbJlQl2G1CVYPVJmNjYwiJ2yZUJdhtQlUDtSkWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, #"Item-Number" = _t, #"Item-Name" = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Item-Number", Int64.Type}, {"Item-Name", type text}, {"Sales", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Item-Number"}, {{"max", each List.Max([Date]), type date}, {"all", each _, type table [Date=date, #"Item-Number"=number, #"Item-Name"=text, Sales=number]}}),
    #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Date", "Item-Name", "Sales"}, {"Date", "Item-Name", "Sales"}),
    #"Added Custom" = Table.AddColumn(#"Expanded all", "Custom", each if [max]=[Date] then [#"Item-Name"] else null),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"Custom"}),
    #"Removed Columns" = Table.RemoveColumns(#"Filled Up",{"max"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @dax , Thanks.

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.