Reply
avatar user
Anonymous
Not applicable
Partially syndicated - Outbound

Get the latest non null value of a serie of column based on another column

I have a table that looks like this:

 

TimestampCol1Col2Col3
T0123
T1null33
T2nullnull5

 

I want to get the latest (based on timestamp) non null value of each column. To at the end get the following one row table:

 

Col1Col2Col3
135

 

How can I do that only with M Formulas in Power Query?

1 ACCEPTED SOLUTION
avatar user
Anonymous
Not applicable

Syndicated - Outbound

Hi @Anonymous 

 

Sorry, updated my original post - have not read your one correct from the first time.

 

This is the updated code, now doing what you need:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjFQ0lEyBGIjIDZWitUBCoG4eaU5OWARuKgRQhRKmSrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Col1 = _t, Col2 = _t, Col3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Timestamp", type text}, {"Col1", Int64.Type}, {"Col2", Int64.Type}, {"Col3", Int64.Type}}),
   
   Output = List.Accumulate(Table.ToColumns(#"Changed Type"), {}, (s, a) => s & {List.Last(List.RemoveNulls(a))}),
    #"Converted to Table" = Table.FromColumns(List.Zip({Output}), Value.Type(#"Changed Type"))

in #"Converted to Table"

 

Kind regards,

JB

 

View solution in original post

1 REPLY 1
avatar user
Anonymous
Not applicable

Syndicated - Outbound

Hi @Anonymous 

 

Sorry, updated my original post - have not read your one correct from the first time.

 

This is the updated code, now doing what you need:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjFQ0lEyBGIjIDZWitUBCoG4eaU5OWARuKgRQhRKmSrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Col1 = _t, Col2 = _t, Col3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Timestamp", type text}, {"Col1", Int64.Type}, {"Col2", Int64.Type}, {"Col3", Int64.Type}}),
   
   Output = List.Accumulate(Table.ToColumns(#"Changed Type"), {}, (s, a) => s & {List.Last(List.RemoveNulls(a))}),
    #"Converted to Table" = Table.FromColumns(List.Zip({Output}), Value.Type(#"Changed Type"))

in #"Converted to Table"

 

Kind regards,

JB

 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)