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: 
victor_jacquens
Contributor II
Contributor II

Data filtering in expression

Hello,

I have an app where I keep track of the stock of some products, and a few of them have a limit on their stock.

I want to create a dimension that only keeps data for these limited products, but I have a problem when writing the expression. I want to keep the 'Class 1' products with category '2' or '3' and the 'Class 5' products with category '3' since they are the only one with a stock limit.

Here's my expression:

=if( [Product Class] = 'Class 1' and [Product Category] = ('2','3'), 'Class 1 Cat.2&3',
if( [Product Class] = 'Class 5' and [Product Category] = '3', 'Class 5 Cat.3'))

The filtering on Class 5 is working fine but with Class 1, I can't seem to filter on 2 different categories.

What should I modify in my expression?

Labels (1)
2 Solutions

Accepted Solutions
GaryGiles
Specialist
Specialist

There are a couple of ways to approach this.  One is to use the Match() function, like this:

=if( [Product Class] = 'Class 1' and Match([Product Category],'2','3')>0, 'Class 1 Cat.2&3',
if( [Product Class] = 'Class 5' and [Product Category] = '3', 'Class 5 Cat.3'))

Basically, the Match() will return the position of the [Product Category] value in the list provided (in this case '2,'3') and returns 0 if it is not found.

View solution in original post

victor_jacquens
Contributor II
Contributor II
Author

Thank you,

I just found another solution, which is:

=if( ([Product Class] = 'Class 1' and [Product Category] = '2') or ([Product Class] = 'Class 1' and [Product Category] = '3'), 'Class 1 Cat.2&3',
if( [Product Class] = 'Class 5' and [Product Category] = '3', 'Class 5 Cat.3'))

View solution in original post

3 Replies
GaryGiles
Specialist
Specialist

There are a couple of ways to approach this.  One is to use the Match() function, like this:

=if( [Product Class] = 'Class 1' and Match([Product Category],'2','3')>0, 'Class 1 Cat.2&3',
if( [Product Class] = 'Class 5' and [Product Category] = '3', 'Class 5 Cat.3'))

Basically, the Match() will return the position of the [Product Category] value in the list provided (in this case '2,'3') and returns 0 if it is not found.

victor_jacquens
Contributor II
Contributor II
Author

Thank you,

I just found another solution, which is:

=if( ([Product Class] = 'Class 1' and [Product Category] = '2') or ([Product Class] = 'Class 1' and [Product Category] = '3'), 'Class 1 Cat.2&3',
if( [Product Class] = 'Class 5' and [Product Category] = '3', 'Class 5 Cat.3'))

GaryGiles
Specialist
Specialist

Like I said, there are multiple approaches.  The Match() function approach has the advantage of being easier to read/write/change, especially if you had many [Product Class] values that you wanted to include.