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

Announcements
Qlik Unveils New Agentic Capabilities Across Analytics, Data Engineering, and Trust: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tMap - IF ELSE statement fails

Hi,

 

I have this table and I'm trying to apply a conditional statement to get a boolean to find out if the 5th position of the field DATE is char "/"

 

0683p000009M6lw.png

 

I've made it in two steps, first I've applied this statement to get the "/" from the 5th position:

StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1)

 

That works, but when I add the contitional expression, It doesn't work and all I got are 0:

StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1) == "/" ? 1:0

 

Could someone help me, please?

 

Thank you!!

 

 

Labels (2)
1 Solution

Accepted Solutions
lennelei
Creator III
Creator III

Hello,

 

== is an operator comparing objects in your example, not their content!

 

Comparing strings can be made with the .equals() method of the String object :

"/".equals(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0

Or with the .equals method of the Objects object (you may have to import it first) :

Objects.equals("/", StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0

You can also use other methods depending on your needs (.compareTo() for example)

View solution in original post

7 Replies
lennelei
Creator III
Creator III

Hello,

 

== is an operator comparing objects in your example, not their content!

 

Comparing strings can be made with the .equals() method of the String object :

"/".equals(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0

Or with the .equals method of the Objects object (you may have to import it first) :

Objects.equals("/", StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0

You can also use other methods depending on your needs (.compareTo() for example)

Anonymous
Not applicable
Author

Thank you!!

 

By the way, now I'm trying to apply the same rule to determine if the 5th and 6th characters are smaller than 12. 

 

<= 12 (StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2)) ?1:0

 

Could you please tell me which would be the correct sentence?

 

Thank you!!

lennelei
Creator III
Creator III

if (StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2)) returns the correct part of the String, and you are sure it will be a number, you may do 

Integer.parseInt(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2))) <= 12

In this case, you can use <= as you are comparing an int primitive with the value 12

Anonymous
Not applicable
Author

Yes, I've tried this sentence, the problem is that not always will be a number, here's an example on which it's "/2":

0683p000009M6Iv.png

lennelei
Creator III
Creator III

Then you should test the value before:

First add a tMap variable testValue with this code :

 

Integer.parseInt(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2)))

And then use this in your test:

 

 

Var.testValue.matches([0-9]+)?Integer.parseInt(Var.testValue)<=12:false

This will test if your substring contains only digits. If yes, this will return if that number is less or equal than 12. If no, this will return false.

 

Anonymous
Not applicable
Author

I've tried adding the testValue and then executing this sentence:

Var.testValue.matches([0-9]+)?Integer.parseInt(Var.testValue)<=12:false

 And I have this error:

0683p000009M69T.png

0683p000009M6K2.png

 

Thank you for your time

lennelei
Creator III
Creator III

Of course, I forgot to quote the regex 0683p000009MPcz.png

Var.testValue.matches("[0-9]+")?Integer.parseInt(Var.testValue)<=12:false