Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Qlik Community
- :
- Forums
- :
- Analytics
- :
- App Development
- :
- Exclude dimension value but don't respect selectio...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

dselgo_eidex

Partner - Creator III

2020-02-18
01:07 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Exclude dimension value but don't respect selections in that dimension

I'll be honest, I don't really know how to title this one properly. I am working with a set of student test data with the following properties:

- Every student has a unique ID
- Every student may or may not have an Ethnicity assigned to them
- Every student has a Gender
- Every student takes either the Math test or the Reading test

My goal is to create a pivot table that does a side-by-side comparison of the count of students in an Ethnicity that took the test vs the count of students NOT in that Ethnicity that took the test. The table has 1 row dimension, 1 column dimension, and 2 measures (one for the count of students in the ethnicity and one for the count of students not in the ethnicity). About 2 months ago I asked a question on how to calculate a measure over the complement of the dimension value (https://community.qlik.com/t5/Qlik-Sense-App-Development/Calculate-measure-over-complement-of-dimens...). This helped me to get the following expression for calculating the complement count of students for an ethnicity

```
pick(
match(Ethnicity, $(='''' & concat(DISTINCT Ethnicity,''',''', Ethnicity) & '''')),
$(=concat({$<Ethnicity -= {''}>} DISTINCT 'count({$<Student = E({$<Ethnicity = {''' & Ethnicity & '''}>} Student)>} TOTAL<Subject> DISTINCT Student)',',',Ethnicity))
)
```

After the dollar-sign expansion, it results in the following:

```
=pick(match(Ethnicity, 'African American','Asian','Hispanic','White'),
count({$<Student = E({$<Ethnicity = {'African American'}>} Student)>} TOTAL<Subject> DISTINCT Student),
count({$<Student = E({$<Ethnicity = {'Asian'}>} Student)>} TOTAL<Subject> DISTINCT Student),
count({$<Student = E({$<Ethnicity = {'Hispanic'}>} Student)>} TOTAL<Subject> DISTINCT Student),
count({$<Student = E({$<Ethnicity = {'White'}>} Student)>} TOTAL<Subject> DISTINCT Student)
)
```

Essentially, for every dimension value (Ethnicity), it will create an expression that will include only the records where the Ethnicity is NOT that value. The E() is used to account for students that do no have an Ethnicity assigned to them. And this works! The expression results in the following table (I've colored the cells to indicate the correct value):

However, as soon as you select an Ethnicity:

Because the expression uses the default state, any selection on the Ethnicity field results in a set of no records for the Exclusion. So I tried changing to the 1 state:

```
pick(
match(Ethnicity, $(='''' & concat(DISTINCT Ethnicity,''',''', Ethnicity) & '''')),
$(=concat({$<Ethnicity -= {''}>} DISTINCT 'count({1<Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>} TOTAL<Subject> DISTINCT Student)',',',Ethnicity))
)
```

And now this works when I make a selection on Ethnicity:

However, when I make a selection on Gender, the number remains the same:

This makes sense, because I am no longer including selections. What I want is for the expression to include the set limited by selections EXCEPT for Ethnicity. I've tried a few different methods but haven't found any success yet. I've attached my sample app to demonstrate this problem.

Any help is appreciated.

719 Views

1 Solution

Accepted Solutions

dselgo_eidex

Partner - Creator III

2020-02-19
12:51 PM

Author

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

So I spent two whole days working on this, and it turns out the correct number was three 😅.

I actually had the answer before posting the question, but I was getting incorrect values. I figured that I could find the results that I wanted by finding the intersection of the default set excluding the selections on Ethnicity and the set of all students not in that ethnicity:

`{$<Ethnicity = 1::Ethnicity> * 1<Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>}`

Unfortunately though, this only includes non-null values for Ethnicity, meaning that my results were off. Through trial and error I got to this set expression:

`{$<Ethnicity> * 1<Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>}`

This finally worked! It passed all of my tests. However, when I loaded it into my actual app, it was incredibly slow because my actual pivot table has a few aggrs in it. I figured that the intersection of the sets was slowing things down, so I kept experimenting until I got this:

`{$<Ethnicity, Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>}`

This created the same results as above, and was much faster to calculate.

I posted the updated app to showcase these findings in case it helps anyone else with a similar problem.

680 Views

1 Reply

dselgo_eidex

Partner - Creator III

2020-02-19
12:51 PM

Author

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

So I spent two whole days working on this, and it turns out the correct number was three 😅.

I actually had the answer before posting the question, but I was getting incorrect values. I figured that I could find the results that I wanted by finding the intersection of the default set excluding the selections on Ethnicity and the set of all students not in that ethnicity:

`{$<Ethnicity = 1::Ethnicity> * 1<Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>}`

Unfortunately though, this only includes non-null values for Ethnicity, meaning that my results were off. Through trial and error I got to this set expression:

`{$<Ethnicity> * 1<Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>}`

This finally worked! It passed all of my tests. However, when I loaded it into my actual app, it was incredibly slow because my actual pivot table has a few aggrs in it. I figured that the intersection of the sets was slowing things down, so I kept experimenting until I got this:

`{$<Ethnicity, Student = E({1<Ethnicity = {''' & Ethnicity & '''}>} Student)>}`

This created the same results as above, and was much faster to calculate.

I posted the updated app to showcase these findings in case it helps anyone else with a similar problem.

681 Views

Community Browser