Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
RoyBatty
Contributor III
Contributor III

Exclusion does not work (set expressions)

Hi,

We have two tables that have only one dimension (user_id) and nothing else:

Table "S Users":

RoyBatty_0-1709157812031.png

 

Table "E Users":

RoyBatty_1-1709157843442.png

For "S Users" we use the following set expression:

=Aggr(
Only({<[Standard Activity Period]={'N'}, [Activity]={'Payment', 'Support'}>} distinct [user_id]),
[user_id]
)

 For "E Users" we use the following set expression (the only difference is 'Y' instead of 'N'):

=Aggr(
Only({<[Standard Activity Period]={'Y'}, [Activity]={'Payment', 'Support'}>} distinct [user_id]),
[user_id]
)

We want to create a third table that will show only those "S Users" that are not in "E Users" (S - E). We tried the following with the Exclusion (-) operator:

=Aggr(
Only(
{
$<[Standard Activity Period]={'N'}, [Activity]={'Payment', 'Support'}>
-
$<[Standard Activity Period]={'Y'}, [Activity]={'Payment', 'Support'}>
}
distinct [user_id]
),
[user_id]
)

but it doesn't work, it gives a wrong result (please see the third table in the image below):

RoyBatty_2-1709158767760.png

 

The expression is probably written incorrectly (there is no error but it does not give the correct result), but we cannot find out what the problem is and how we can solve this.

Do you have any ideas or suggestions as to what that expression should look like? Thanks in advance!

 

Labels (1)
1 Solution

Accepted Solutions
ali_hijazi
Partner - Master II
Partner - Master II

Let me explain to you:

ali_hijazi_0-1709193082915.png

I tried to mimic your situation
in the first table I'm dispaying users where type = Y and profession ={IT,support}
in the second table I'm displaying users where type = N and profession {IT,support}

now with your approach ali, and jean will appear 
so you want to exclude users who only have type = Y
so your expression would be :
aggr(Only{<user={"=type='Y'"}>}user),user)

and this is what is displayed in the last table to the right

the data that I used is as follows:
load * Inline [
user, type, profession
ali, Y, support
ali, N, IT
jean, Y, IT
maher, N, support
amir, Y, home
omar, N, IT
];

the expressions used in the tables are:
1.=aggr(only({<type={Y},profession={[support],[it]} >}user),user)
2.=aggr(only({<type={N},profession={[support],[it]} >}user),user)
3.=aggr(only({
<type={Y},profession={[support],[it]} >
-
<type={N},profession={[support],[it]} >
}user),user)

4. =aggr(only({
<user={"=type='Y'"},profession={[support],[it]} >

}user),user)

hope this helps

I can walk on water when it freezes

View solution in original post

4 Replies
Zapparoli
Creator II
Creator II

I'm not really sure why you did those expression, let me know if i'm missing something, but this is what I would do:

If your table has the, User ID, Standard Activity Period and the Activity fields, you could do:

aggr(
    		 Only(
  				  {<ActivityPeriod={'Y'}
				
				  >}
      user_id) , user_id)

Basically, you are getting only the fields that contains the "Y" on the Standard Activity Period Field, then I use Aggr by user_id, and return only the field that I want:

Zapparoli_0-1709164800463.png

 

Let me know if this helps you.

-Zapparoli

Check my Youtube Channel for more Qlik Content
https://www.youtube.com/@ZappaAnalytics

ali_hijazi
Partner - Master II
Partner - Master II

sometimes we use this approach when there is no expression to be computed
so as he's saying above, we wants to list the dimension values satisfying some conditions

I can walk on water when it freezes
ali_hijazi
Partner - Master II
Partner - Master II

Let me explain to you:

ali_hijazi_0-1709193082915.png

I tried to mimic your situation
in the first table I'm dispaying users where type = Y and profession ={IT,support}
in the second table I'm displaying users where type = N and profession {IT,support}

now with your approach ali, and jean will appear 
so you want to exclude users who only have type = Y
so your expression would be :
aggr(Only{<user={"=type='Y'"}>}user),user)

and this is what is displayed in the last table to the right

the data that I used is as follows:
load * Inline [
user, type, profession
ali, Y, support
ali, N, IT
jean, Y, IT
maher, N, support
amir, Y, home
omar, N, IT
];

the expressions used in the tables are:
1.=aggr(only({<type={Y},profession={[support],[it]} >}user),user)
2.=aggr(only({<type={N},profession={[support],[it]} >}user),user)
3.=aggr(only({
<type={Y},profession={[support],[it]} >
-
<type={N},profession={[support],[it]} >
}user),user)

4. =aggr(only({
<user={"=type='Y'"},profession={[support],[it]} >

}user),user)

hope this helps

I can walk on water when it freezes
RoyBatty
Contributor III
Contributor III
Author

Thank you so much!