Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Barry Harmsen posted an amazing example app to his blog (QlikFix.com) in October of 2013. The example creates a way to do AND / OR selections with Qlikview. This turns out to be exactly what I need, but I'm going crazy trying to understand all of Barry's work.
For reference, the blog post is at:
Or-mode selections in QlikView The Qlik Fix!
There is also an example QVW there. I've loaded the example and found all of the places where things happen. The real work takes place in calculations that are part of a variable, and that's where I'm having trouble. The variable is: vSelection.Or, and the calculation is:
=$(=
Concat(DISTINCT {<[$Field]-={$(vSelection.IgnoreFields)}>}
'If(GetSelectedCount([' & [$Field] & ']) > 0, ' & chr(39) &
'<[' & chr(39) & ' & Concat(DISTINCT {<[$Field]={"*"} -
{'& chr(36) & '(vSelection.IgnoreFields)} - {' & chr(39) &
[$Field] & chr(39) & '}>} [$Field], ' & chr(39) & ']= ,[' &
chr(39) & ') & ' & chr(39) & ']= > + ' & chr(39) & ')' , ' & ')
)
I'm having trouble in understanding this. Because it's a series of (what is effectively) nested elements, it would really help if there was formatting applied. That's were I'm having trouble. For example, separating the Concat portions from the IF statement, and the parts of the IF statement from the macro expansions.
Can anybody (who can read the expression) type it into an indented, formatted form? This would be much appreciated. Better yet, my goal is to understand, so additional notes would really help. For example, I know what things like chr(39) mean, but it's hard to sort out where they're necessary because of the interpreter requirements.
Thanks in advance,
Gary
Perhaps it's easier to understand by starting with the expression with a selection in Customer and in Product. That will look like this:
sum(
{<[%Customer id]= ,[%Date id]= ,[%Product id]= ,[%Salesman id]= ,[Date]= ,[Product]= ,[Sales amount]= ,[Salesman]= >
+
<[%Customer id]= ,[%Date id]= ,[%Product id]= ,[%Salesman id]= ,[Customer]= ,[Date]= ,[Sales amount]= ,[Salesman]= >}
Sales)
The blue line is to include the selections in the Customer field. All other fields all ignored. That includes selections in the Product field (in bold) since those would be And-ed with the selections in the Customer field. Since we want an Or-selection the Product field needs to be ignored. But not the Customer field so that's why Customer is not in list of fields in this set modifier.
The red line is to include the selections in the Product field. Here all other fields including the Customer field are ignored.
The two set modifiers are combined with the + operater so we get an Or-selection from the Product and Customer fields.
That's what the outer concat is for; combining the set modifiers for each field with selections into an Or-selection: <set1>+<set2>+..etc
The inner concat is to generate the set modifier with the list of fields that should be ignored, adding [FieldX]= , for each field (except those in the except list in the variable vSelection.IgnoreFields). The internal $Field field is used to 'loop' through all the field names.
The if statement is to skip all fields without a selection. Only for the fields with a selection is a set modifier created using the inner concat.
That's the high level overview. To actually make it work some dollar-expansion is necessary which makes it all a pita to write. I hope this helps.