Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
ankit7359
Creator II
Creator II

Using local variable in tmap expression builder

Hi,

I was wondering if we can write if-else statement in the expression builder of Tmap, also can we write case statements?? if yes how can we write these both??

Thanks in advance

Labels (2)
3 Replies
Anonymous
Not applicable

You can write in-line IF statements in the tMap, like below....

 

row1.myIntColumn == 1 ? "MyValueIsOne" : "MyValueIsNotOne"

You can also combine IF statements like so....

row1.myIntColumn == 1 ? "MyValueIsOne" : row1.myIntColumn == 2 ? "MyValueIsTwo" : "MyValueIsNeitherOneOrTwo"

If you want to use a case statement, you should write it into a Routine. Anything that requires more than one statement needs to be done using a Routine.

 

However you *could* potentially use tMap variables (the box in the middle of the tMap window) to carry out a case statement. Set up each of the cases in the variables using an IF statement in each one. If the IF is true, output a value, if not output null. Then in your last tMap variable, check the values of each of tmap variables (each of the cases) and return the one which is not null. This is probably a bit more complicated than just using a Routine however.

ankit7359
Creator II
Creator II
Author

so in tmap we have to use ternary operators and write if-else statement.

but for case statement - how can we call a routine onto a tmap expression builder 

can u give small example on the same

thanks

 

Anonymous
Not applicable

Here is a basic example of a Case statement in a routine....

package routines;

public class SwitchExample {

    
	public static String intToString(int i){
		String returnVal = "";
		
		switch (i) {
        case 1:  returnVal = "One";
                 break;
        case 2:  returnVal = "Two";
                 break;
        case 3:  returnVal = "Three";
                 break;
        case 4:  returnVal = "Fourl";
                 break;
        case 5:  returnVal = "Five";
                 break;
        case 6:  returnVal = "Six";
                 break;
        case 7:  returnVal = "Seven";
                 break;
        case 8:  returnVal = "Eight";
                 break;
        case 9:  returnVal = "Nine";
                 break;
        case 10: returnVal = "Ten";
                 break;
        default: returnVal = "Greater Than Ten";
                 break;
		}
		
		return returnVal;
		
	}
	
}

To use it in a tMap, you would just call it like this.....

 

routines.SwitchExample.intToString(row.myIntValue)