Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I'm trying to write a if else function in script to modify some strings, for example:
Original strings:
Index
A
B
Chris
Doug
Target output:
Name
Alex
Brad
Chris
Doug
My script:
If(Index = 'A', 'Alex', If(Index = 'B', 'Brad', XXX)) as Name
What should I put into XXX if I don't want to list what I already have in [Index]('Chris' & 'Doug' in this case) and keep them as they are in [Index]?
If(Index = 'A', 'Alex', If(Index = 'B', 'Brad', Index)) as Name
Check out what I've done here using a mapping load and the ApplyMap function.
Good luck!
Oscar
A quick note on the ApplyMap function.
You can pass two required parameters or a third optional parameter.
The two required parameters are the Map Name (1st) the Lookup value (2nd) and finally the optional parameter of a default value returned if not found. In the two parameter version the 2nd parameter will be used as the default value.
Thanks again
Oscar
If(Index = 'A', 'Alex', If(Index = 'B', 'Brad', Index)) as Name
A reason to consider using the ApplyMap function instead of the IF statement is when you have more than a handful of checks that you need to do. That IF statement is going to get huge when you have ten or more values to check.
Just my two cents...
Thank you Oscar, that's pretty useful advice. Right now I only have a small list, but ApplyMap is definitely useful when the list is huge.