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: 
Saryk
Partner - Creator II
Partner - Creator II

Filter by dimension

I'd like to add a filter by dimension instead of by value ; say I have field A {1, 2, 3} and field B {4, 5, 6} that correspond for example to number of sales for employee A and employee B or each product.

I want a pie chart with sales per product, so I have a dimension that is "Product name" and a measure that is Sum(A) + Sum(B).

If I add a filter item (the last one in graphs, I have Qliksense in French which doesn't help, sorry for mistranslations), I can only add a Dimension which then shows all values to filter by Value. 

I want to be able to select A or B to show their individual sales on the same chart, how can I filter this ?

Reality is more complex than that but the analogy simplifies things for explanation purposes.

1 Solution

Accepted Solutions
cpomeren003
Partner - Creator II
Partner - Creator II

Oops, attached wrong document, second try.


View solution in original post

28 Replies
cpomeren003
Partner - Creator II
Partner - Creator II

Can you share your file?

Or can you share an example data + a clear description of the desired end product (an edited image would work as well). 

The reason I ask is because your text doesn't make sense to me at all (maybe because it's friday). I do get the feeling that this can be easily solved by using a set expression or by using alternate states, etc. There are enough options, but I just don't understand what you are saying.

Saryk
Partner - Creator II
Partner - Creator II
Author

Actually I feel stupid now. Yes, it's merely a matter of alternative measures. Is there a way to pull the selection of alternative measures out of the graph itself (if that makes sense)... I would like the option to select the measure be clearly shown in a separate box. 

cpomeren003
Partner - Creator II
Partner - Creator II

Yes, you can, by using a filter object.

Step 1:
Make values for you filter object in the script editor, so something like this

SelectionSaryk:
LOAD * Inline [
Options
"Option A",
"Option B"
];


Then reload your data.

Step 2:
Throw in a "Filter pane" chart and as dimension chose your newly created "Options".

Step 3:
Add in a "Pie chart" and use desired data. Then edit your measure to make it look like this:

=if(GetSelectedCount(Options) = 0, Sum(SaleProductA + SaleProductB),
    Sum(
    	if(WildMatch(GetFieldSelections(Options), '*Option A*') = 1, SaleProductA, 0)
        + if(WildMatch(GetFieldSelections(Options), '*Option B*') = 1, SaleProductB, 0)
    	)
	)


Optional:
You could also add a value "Option A + B" and then force "Always one selected value" on the "Options" field. Depends on personal preference. Just remember that if you do decide to go that way, you need to make some small edits to your measure.

I have also attached an example.

Hope it helps!

Saryk
Partner - Creator II
Partner - Creator II
Author

I changed the first line from 

=if(GetSelectedCount(Options) = 0, Sum(SaleProductA + SaleProductB)

to

=if(GetSelectedCount(Options) = 0, Sum(SaleProductA) + Sum(SaleProductB)

 to get the graph when nothing is selected.

 

I do however still have an issue, and I think it is caused by the fact I have in my options 

SelectionSaryk:
LOAD * Inline [
Options
"B",
"A without B"
"C"
];

and the second one gets matched twice. 

I tried changing the second part of the code to  

=if(GetSelectedCount(Options) = 0, Sum(SaleProductA) + Sum(SaleProductB),
(
    if(Match(GetFieldSelections(Options), 'B') = 1, Sum(SaleProductB), 0) +
    if(Match(GetFieldSelections(Options), 'A without B') = 1, Sum(SaleProductAwB), 0) +
    if(Match(GetFieldSelections(Options), 'C') = 1, Sum(SaleProductC), 0)
)

 But when I select "A without B" and "B" (to have the entirety of "A"), I get a message that says "The graphs isn't shown because it contains only negative or 0 values" (on-the-fly translation) ; while both "B" and "A without B" show the graphs properly.

I can't seem to find the error in the code, could you have a look ? 

cpomeren003
Partner - Creator II
Partner - Creator II

The problem is, your value of "A without B" will match with both "B" and "A without B". You can solve this by replacing "B" with for example "Only B", this way "A without B" won't match.

Other solution would be to make a more complex measure that will for example look at the length as well etc.

Saryk
Partner - Creator II
Partner - Creator II
Author

I can indeed find ways to fix that, but if I select "B" and "C" - or any number more than one for that matter - I get the same "graph not showing" issue.

 

Saryk
Partner - Creator II
Partner - Creator II
Author

If I check the data, with "C" selected I have, say, 18 ; with "B" selected I have 12, but with both selected I have 0.

cpomeren003
Partner - Creator II
Partner - Creator II

That's strange, can you share your file? Because in the example I attached to my previous post you can show multiple without a problem.

cpomeren003
Partner - Creator II
Partner - Creator II

I think the problem lies in your change from WildMatch -> Match. Can you try this:

=if(GetSelectedCount(Options) = 0, Sum(SaleProductA) + Sum(SaleProductB),
(
    if(WildMatch(GetFieldSelections(Options), '*B*') = 1, Sum(SaleProductB), 0) +
    if(WildMatch(GetFieldSelections(Options), '*A without B*') = 1, Sum(SaleProductAwB), 0) +
    if(WildMatch(GetFieldSelections(Options), '*C*') = 1, Sum(SaleProductC), 0)
)

I basically changed Match back to WildMatch and reintroduced the *'s.