Forum Discussion
Nearest match from TABLE1 to Table2
- 3 years ago
Hi Topaz_Installer,
You can copy this into a new blank query
let Tbl1 = Table.TransformColumnTypes(Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMgAhpVgdOMcUiWOILGMIlIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Table1 = _t]),{{"Table1", type time}}), Tbl2 = Table.TransformColumnTypes(Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMgAhpVgdOMcQmWOGxDFEVmYIlIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Table2 = _t]),{{"Table2", type time}}), AddCustom = Table.AddColumn(Tbl1, "Approx Match", each List.First( Table.SelectRows( Tbl2, (x)=> x[Table2] >= [Table1])[Table2] ), type time) in AddCustomGive this a go for an approx match
Table.AddColumn( Tbl1, "Approx Match", each List.First( Table.SelectRows( Tbl2, (x)=> x[Table2] >= [Table1])[Table2] ), type time)
with this result
Ps. If this helps solve your query please mark this post as Solution, thanks!
- 3 years ago
let Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMgAhpVgdOMcMiWOILGMIlIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Timestamp = _t]), #"Changed Type Table2" = Table.TransformColumnTypes(Table2,{{"Timestamp", type time}}), Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMgAhpVgdOMcUiWOILGMIlIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Timestamp = _t]), #"Changed Type Table1" = Table.TransformColumnTypes(Table1,{{"Timestamp", type time}}), #"Added Match" = let l = #"Changed Type Table2"[Timestamp] in Table.AddColumn( #"Changed Type Table1", "Match", each let dev = List.Transform(l, (ts) => Number.Abs(Number.From(ts - [Timestamp]))), pos = List.PositionOf(dev, List.Min(dev)) in l{pos} ) in #"Added Match"A showcase of powerful Excel worksheet formulas,
=INDEX(Table2[Timestamp];LET(dev;ABS(Table2[Timestamp]-[@Timestamp]);MATCH(MIN(dev);dev;)))
Hi Topaz_Installer,
You can copy this into a new blank query
let
Tbl1 = Table.TransformColumnTypes(Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMgAhpVgdOMcUiWOILGMIlIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Table1 = _t]),{{"Table1", type time}}),
Tbl2 = Table.TransformColumnTypes(Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSwMgAhpVgdOMcQmWOGxDFEVmYIlIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Table2 = _t]),{{"Table2", type time}}),
AddCustom = Table.AddColumn(Tbl1, "Approx Match", each List.First( Table.SelectRows( Tbl2, (x)=> x[Table2] >= [Table1])[Table2] ), type time)
in
AddCustom
Give this a go for an approx match
Table.AddColumn( Tbl1, "Approx Match", each List.First( Table.SelectRows( Tbl2, (x)=> x[Table2] >= [Table1])[Table2] ), type time)
with this result
Ps. If this helps solve your query please mark this post as Solution, thanks!
Thank you for the help and much appreciated. Please let me know how convert table or csv file to JSON format in power query as when I use table or csv, because of data size loading or refreshing very slow. please guide me how I can make my query loading faster