Forum Discussion
explain this custom function, please?
I found a function to replace text using a lookup table. It works great. But the syntax is unfamiliar to me and I can't find a reference for it. Here's what I have:
replacer = (x,y,z)=>LookupTable{[#"lookup value"=x]}?[replacement]? ??x
I have 3 questions about the above:
- why does the =x go inside the column reference? LookupTable{[#"lookup value"=x]}
- where is the documentation for what looks like a ternary operator in M? a?b? ??c
- why doesn't the column reference in the true portion of the statement need to be fully justified with the table name? [replacement]
Hi halifaxious,
There is a lot going on here
replacer = (x,y,z)=>LookupTable{[#"lookup value"=x]}?[replacement]? ??xFirst this is a custom replacer function which takes 3 arguments:
x = original value
y = match condition (true or false)
z = replacement value
Next its applying (optional) key match lookup to identify a unique row in the table
LookupTable{ [#"lookup value"=x] }?
Followed by (optional) field access, to return a value from a field/ column
[replacement]?
And finally applying coalesce, to return the input value if a null is returned.
?? x
Ps. If this helps solve your query please mark this post as Solution, thanks!
Some links to resources on these topics:
Visual guide to key match lookup
2 Replies
- m_dekorteResident Rockstar
Hi halifaxious,
There is a lot going on here
replacer = (x,y,z)=>LookupTable{[#"lookup value"=x]}?[replacement]? ??xFirst this is a custom replacer function which takes 3 arguments:
x = original value
y = match condition (true or false)
z = replacement value
Next its applying (optional) key match lookup to identify a unique row in the table
LookupTable{ [#"lookup value"=x] }?
Followed by (optional) field access, to return a value from a field/ column
[replacement]?
And finally applying coalesce, to return the input value if a null is returned.
?? x
Ps. If this helps solve your query please mark this post as Solution, thanks!
Some links to resources on these topics:
Visual guide to key match lookup
- halifaxiousFrequent Visitor
Thank you for a very illuminating answer! I wish I'd come here about 2 hours ago instead of fruitlessly googling.