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: 
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Best expression to test for field value

I'm looking for the "best" expression to test if the current possibles of a field contains one or more values. For example:

if( Region contains 'US",

By best, I mean fast, compact easy to write, and no redundancy. In the past (pre Set Analysis) I've used

sum(if(Region='US',1))>0

With Set Analysis I'm using:

count({$*<Region={US}>}DISTINCT Region)>0

but I don't like having to type "Region" twice. I know I've seen some more clever forms posted here. Anyone have a better suggestion?

Thanks,

Rob

1 Solution

Accepted Solutions
jerem1234
Specialist II
Specialist II

Maybe this could be an alternative:

max(match(Region, 'US'))>0

View solution in original post

7 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi Rob,

You can arrive a Flag in your script with 1 for Region US and just use this expression

Data:

LOAD

*,

If(Region = 'US', 1, 0) AS Flag

FROM DataSource;

=Sum(Flag) > 0

Regards,

Jagan.

marcus_sommer

Hi Rob,

maybe this $Field question is helpful.

- Marcus

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP
Author

Hi Jagan,

Thanks for the suggestion, but script is not flexible enough. I'm looking for a chart expression.

-Rob

angelaecheverri
Creator
Creator

I will do it like this...

count({<Region={'US'}>} DISTINCT Region)

Note that US must be into  '' becuase is not a number.


this expression will count how many DISTINCT regions will have registres which region is us....


count(DISTINCT Region)

will show you how many regions are by the dimension you have exposed...



jerem1234
Specialist II
Specialist II

Maybe this could be an alternative:

max(match(Region, 'US'))>0

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP
Author

I like that one Jerem. I'll test the performance on some large sets.

Edit: I tested on some very large datasets and it performs well!

-Rob

jagan
Luminary Alumni
Luminary Alumni

Hi Rob,

Check this, this is more better than using Match, because we are using Set Analysis

=MaxString({<Region={'US'}>} Region) > 0

Regards,

Jagan.