Filter based on max value of other query
Lets assume we're having these two tables:
table_a
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzMGmuFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}})
in
#"Changed Type"
table_b
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzMGkOJi3ApCWYNDSAUBDdhkDtsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column9 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column9", Int64.Type}})
in
#"Changed Type"
Goal:
I want to filter table_b like all values equal or less than max value from table_a
.
In R or Python I'd do it like:
# R (data.table)
table_b[Column9 <= max(table_a$Column1)]
# Python (pandas)
table_b[table_b["Column9"] <= table_a["Column1"].max()]
But I have no idea how to solve this in M.
Solution 1:
In table_b, add a Table.SelectRows that references max value of Column1 in table_a which is List.Max(table_a[Column1])
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzMGkOJi3ApCWYNDSAUBDdhkDtsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column9 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column9", Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Column9] <= List.Max(table_a[Column1]))
in #"Filtered Rows"