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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors