Forum Discussion
Power Query Structured lookup
- 1 year ago
There are some more examples that may confuse you. If you can understand them, then you understand "field access" (and projection) and the keyword each.
// Example 1 [A = 1, B = 2][[A], [C]]? // Example 2 #table({"A", "B"}, {{1, 2}, {1, 3}})[[D]]? // Example 3 let _ = [ A = 1, B = 2 ] in [A] // Example 4 let _ = [ A = 1, B = 2 ] in _[[A], [C]]?
This is a native syntax that means find the only row in the table that meets the conditions.
You can find its usage in the Power Query documentation.
https://learn.microsoft.com/en-us/powerquery-m/m-spec-operators#selection-and-projection-operators
For example, tbl{[A=1, B=2]) means to find the row in table tbl where column A is equal to 1 and column B is equal to 2 (return a record value).
You may know that the operator ? can prevent errors when an item or field does not exist, but it may not work here. The operator ? can only avoid not being found. If multiple rows that meet the conditions are found, an error will still be returned.
// null
Table.FromValue({1, 2, 3, 3}){[Value = 4]}?
// error
Table.FromValue({1, 2, 3, 3}){[Value = 3]}?
Thanks I'll have a look,
I'll leave this open for a bit and see if anyone else has reading suggestions.
Richad.