Forum Discussion
TTS
2 years agoFrequent Visitor
Latest value by key column
Tried to go through community cases and other help platforms but group by with fill down did not solve the issue. The data I am receiving from source system: - ID's can get values or nulls ...
- 2 years ago
let Source = your_table, names = List.Buffer(List.Skip(Table.ColumnNames(Source), 2)), f = (tbl) => [sorted = List.Skip(Table.ToColumns(Table.Sort(tbl, "Date")), 2), rec = Record.FromList( List.Transform(sorted, (x) => try List.Last(List.RemoveNulls(x)) otherwise null), names )][rec], group = Table.Group(Source, "ID", {"x", f}), xp = Table.ExpandRecordColumn(group, "x", names) in xp - 2 years ago
Hi TTS, different approach here:
Enter column names you want to calculated MAX here:
Result
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDLRNTAEIiAnLDGnNBWDjtWJVjLCpRSEQAqM0RVAEMIEZMuMDGBSRkhGGKGrQFYEZaBbhVNdLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Column1 = _t, Column2 = _t, Column3 = _t]), // You can probably delete this step. ReplaceBlankToNull = Table.TransformColumns(Source, {}, each if _ = "" then null else _), ChangedType = Table.TransformColumnTypes(ReplaceBlankToNull,{{"ID", Int64.Type}, {"Date", type date}}), __EnterColumnsHere__ = {"Column1", "Column2", "Column3"}, GroupedRows = Table.Group(ChangedType, {"ID"}, {{"MaxValue", each [ a = List.Transform(__EnterColumnsHere__, (x)=> List.Max(Table.Column(_, x))), b = Table.FromRows({ {[ID]{0}} & a }, {"ID"} & __EnterColumnsHere__) ][b], type table}}), CombinedMaxValue = Table.Combine(GroupedRows[MaxValue]) in CombinedMaxValue
AlienSx
2 years agoSuper User
let
Source = your_table,
names = List.Buffer(List.Skip(Table.ColumnNames(Source), 2)),
f = (tbl) =>
[sorted = List.Skip(Table.ToColumns(Table.Sort(tbl, "Date")), 2),
rec = Record.FromList(
List.Transform(sorted, (x) => try List.Last(List.RemoveNulls(x)) otherwise null),
names
)][rec],
group = Table.Group(Source, "ID", {"x", f}),
xp = Table.ExpandRecordColumn(group, "x", names)
in
xpTTS
2 years agoFrequent Visitor
Thanks for this input!
Actually I got it working now!!! Great thanks!