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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] tMap Expression Builder - multiple else if

Hi all,
I have a simple project with a tFileInputDelimited, tMap, and tMysqlOutput components. I'm trying to build a calculated field in the tMap component Expression builder, but all my attempts have failed to compile at this point. What I'm doing is fairly straight forward, in php it would look something like this:
if ($custPrice>0) {
// sale
if ($promoCode=='GP') {
$revenueType='G';
} else {
$revenueType='S';
}
} else if ($custPrice<0) {
// return/refund
$revenueType='R';
} else {
// no charge
if ($promoCode=='GR') {
$revenueType='D';
} else if ($productTypeIdentifier=='7' || $productTypeIdentifier=='7T' || $productTypeIdentifier=='7F') {
// upgrade
$revenueType='U';
} else if ($productTypeIdentifier=='1' || $productTypeIdentifier=='1T' || $productTypeIdentifier=='1F') {
// comp
$revenueType='C';
} else {
// other! not expected
$revenueType='O';
}
}

Basically the revenueType G, S, R, U or C is what I want to return to the output column. I seem to be able to do individual row1.column.equals lines properly - Is it possible to do in one expression in Talend? Or a better way to handle this?
Thanks!
Labels (2)
1 Solution

Accepted Solutions
alevy
Specialist
Specialist

Simply
row1.custPrice>0
?row1.promoCode.equals("GP")
?"G"
:"S"
:row1.custPrice<0
?"R"
:row1.promoCode.equals("GR")
?"D"
:row1.productTypeIdentifier.matches("7|7T|7F")
?"U"
:row1.productTypeIdentifier.matches("1|1T|1F")
?"C"
:"O"

The whitespace is irrelevant but included for ease of reading. I've used a regex .matches comparison rather than multiple .equals comparison for simplicity.

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Hi
The convenientest way is to create a custom routine(a java method) in Talend Studio.
Regards,
Pedro
alevy
Specialist
Specialist

Simply
row1.custPrice>0
?row1.promoCode.equals("GP")
?"G"
:"S"
:row1.custPrice<0
?"R"
:row1.promoCode.equals("GR")
?"D"
:row1.productTypeIdentifier.matches("7|7T|7F")
?"U"
:row1.productTypeIdentifier.matches("1|1T|1F")
?"C"
:"O"

The whitespace is irrelevant but included for ease of reading. I've used a regex .matches comparison rather than multiple .equals comparison for simplicity.
Anonymous
Not applicable
Author

alevy - thanks so much - that did the trick!