Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

We need this dimension and we don't need it, both at the same time (set analysis)

Let's say we have a data table of Meals Served.  In Qlikview 11 we have a straight table chart, with Waiter as the dimension.  For each Waiter, we can see the number and value of the meals that he/she served.


But now I have to add a new column to this table, showing the value of Meals Eaten by This Waiter.  The problem is, I still need the first column in the table to show each Waiter. 


Imagine Waiter 1 ate a few meals.  But he wasn't the waiter for any of those, so they are not part of the data set in my straight table chart for the row that shows Waiter 1.  So I figured I could do Set Analysis to find the value of meals eaten by Waiter 1.  Override the dimension and sum up the meals where Waiter 1 is the eater.  But as soon as I override the dimension, then Qlikview no longer knows that I am thinking of Waiter 1. 


For instance,


sum(if(Waiter <> Eater,mealvalue,0))

doesn't work, that just gives us the meals that this Waiter served, that someone else ate.  Since we need to look at meals that this Waiter did not serve, I think we have to do set analysis.

And we can't say Waiter=Eater for the same reason, in my chart that only looks at rows where the Waiter is the server, so it won't bring back any result.


sum({<Waiter=>} TOTAL mealvalue)

sum({1} TOTAL mealvalue)

These don't work, because they add up all the meals for all Waiters.   I need each Waiter's eating to show up on "his" row in the chart.

I want to tell Qlikview to add up the meal values eaten by the Waiter on each row of the chart, but those meals are not in the data set for that Waiter's Meals Served. 

Does anybody have an idea how to get around this situation?  Thanking you in advance for any hints you might have.

3 Replies
swuehl
MVP
MVP

I think the problem is that a real life person acts in two different roles, waiter and eater, while you are modelling your data by only the two roles using two fields and grouping your data by only one role, waiter in the chart.

The solution might be to use a model with person and role as fields and to use person as dimension, and filter your data by role for the served and eaten chart columns using set analysis.

To transform your data from a data model that has waiter and eater as columns to a model that has person and role as columns, you can probably use the CROSSTABLE LOAD prefix in your script.

If you can describe your model a bit closer and maybe create some sample data in a QVW, I believe someone here around can help you with the syntax in the load script and chart.

stephencredmond
Luminary Alumni
Luminary Alumni

Hi,

Probably need to look at your data model.

If you are storing "Eater" and "Waiter" on the same line, you aren't going to be able to calculate them as you propose.  There are a couple of solutions.  One would be to have a data island for the waiters and then you could have a sum of an if statement to calculate the eater and waiters.  I would prefer to see a data model with a link table and role.

See the attached example.  Once implemented, the calculation is trivial.

Regards,

Stephen

Stephen Redmond is author of QlikView for Developer's Cookbook

He is CTO of CapricornVentis a QlikView Elite Partner. We are always looking for the right people to join our team.

Follow me on Twitter: @stephencredmond

Not applicable
Author

I wish to thank you both for your helpful answers!  Note how you are both thinking along the same line.  I realized that the dimension was the source of my problem, but not that it was also the ticket to a solution.  I have revised my data model along the lines that you suggested, so now our dimension is more general and not tied to just one role.  This enables us to pinpoint the right data in our expression columns.  Again, many thanks to you and to the Qlikview Community.