Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If... else...

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]?

1 Solution

Accepted Solutions
dan_sullivan
Creator II
Creator II

If(Index = 'A', 'Alex', If(Index = 'B', 'Brad', Index)) as Name

View solution in original post

5 Replies
oscar_ortiz
Partner - Specialist
Partner - Specialist

Check out what I've done here using a mapping load and the ApplyMap function.

Good luck!

Oscar

oscar_ortiz
Partner - Specialist
Partner - Specialist

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

dan_sullivan
Creator II
Creator II

If(Index = 'A', 'Alex', If(Index = 'B', 'Brad', Index)) as Name

oscar_ortiz
Partner - Specialist
Partner - Specialist

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...

Not applicable
Author

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.