Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Anonymous
Not applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Get the latest non null value of a serie of column based on another column
12-18-2019
08:08 AM
I have a table that looks like this:
Timestamp | Col1 | Col2 | Col3 |
T0 | 1 | 2 | 3 |
T1 | null | 3 | 3 |
T2 | null | null | 5 |
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:
Col1 | Col2 | Col3 |
1 | 3 | 5 |
How can I do that only with M Formulas in Power Query?
Solved! Go to Solution.
1 ACCEPTED SOLUTION

Anonymous
Not applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019
09:09 AM

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
1 REPLY 1

Anonymous
Not applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019
09:09 AM

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
Recommendations
Subject | Author | Posted | |
---|---|---|---|
07-30-2024 07:42 AM | |||
Anonymous
| 12-28-2023 06:37 PM | ||
08-21-2023 02:15 AM | |||
02-25-2024 01:26 AM | |||
01-17-2024 11:27 AM |