Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
tomf122
Contributor III

Like operator in an expression

Is it possible to use a like expression in an expression for a chart. 

I currently have the below logic:

if(match (MVT,'311','312','411')
, count({<MVT={'311','312','411'},Numeric={'0','1'}>} MVT)/2,

if(MVT = '201'
, count({<MVT={'201'},Numeric={'0','1'}>}MVT)))

I would like to add the following to only account for locations which begin with A-Z.

sloc like '[A-Z]%'

Is this possible in Qlicksense or does this need to be done back in the data source by creating an indicator which i can then use.

Thanks,

Tom

Labels (1)
4 Replies
Or
MVP

In Qlik, WildMatch() would be used instead of SQL's like, but regexp is not supported. A simple condition like "Begins with a letter" could be done using string testing, or ascii number checking, or any number of other (clunkier) methods, though.

Have a look at https://community.qlik.com/t5/App-Development/How-to-load-data-that-matches-regular-expression/m-p/1...for workarounds.

maxgro
MVP

Maybe you can test if the first char is >= 'A' and <= 'Z'.

 

T:
LOAD * inline [
word
acd
Acd
123
z1234
!!!!!
|||||

$$$$$
""""""
/////
];

T2:
NOCONCATENATE LOAD * RESIDENT T
WHERE
(LEFT(word,1) >= chr(ord('a')) AND LEFT(word,1) <= chr(ord('z')))
OR
LEFT(word,1) >= chr(ord('A')) AND LEFT(word,1) <= chr(ord('Z'))
;

DROP TABLE T;

marcus_sommer

In general it's possible to query such conditions in UI expressions. But it will depend on the particular scenario which way could be used and how suitable it would be in regard to the efforts and a possible performance impact.

I just played a bit with dummy data like:

load chr(recno() + 33) as Char, recno() as RecNo, 1 as Value autogenerate 120;

Pure theoretically it should be possible to use relational string operators like precedes and follows - but the "classical" set analysis syntax seems not to be applicable so that a if-loop syntax would be needed, like:

sum({< Char = {"=(Char follows 'A' and Char precedes 'Z') or Char = 'A' or Char = 'Z'"}>} Value)

whereby these operators doesn't be case sensitive and the char '@' which comes before 'A' creates rather strange results - which leads to the additionally or statement within the condition. If anyone has more experience with this feature please share your knowledge.

Another approach would be to create an appropriate search-string for the set analysis with something like:

sum({< Char = {"$(=concat(chr(valueloop(65,90,1)), '*","') & '*')"}>} Value)

which worked fine - but is also not case sensitive.

If the consideration of the case-sensitive is mandatory a classical if-loop will be needed, for example with:

if(match(left(Char, 1), '$(=concat(chr(valueloop(65,90,1)), ''',''') & '*')'), sum(Value))


If none of the mentioned approaches are practically enough you could of course flag these cases and/or by various of such requirements to categorize them within the script.

- Marcus

 

 

 

 

MarcoWedel

one crude way to check for locations starting with a letter could also be:

 

Upper(Left(sloc,1))<>Lower(Left(sloc,1))

 

but then again, as the number of possible letters tends to be constant you could as well use:

Index('ABCDEFGHIJKLMNOPQRSTUVWXYZ',Left(sloc,1))

as a boolean expression.