QlikView Alternate States Use-Cases

QlikView Alternate States - Featured Image - Altered States Movie

I was recently invited to do a presentation on QlikView Alternate States and it’s use-cases.  So I created an example application and thought it should be shared here as well.  This is a feature that was added in the first version of QV11.  It is extremely powerful especially for QlikView Comparative Analysis.

You can download the sample application:  Alternate States Use-Cases.qvw

QlikView Alternate States – What is it?

The concept of Alternate States is that we can create “copies” of the data model within the QlikView application.  These copies can then be referenced at the sheet, object or expression level.  It’s like creating parallel universes where we can look at each universe side-by-side, making comparisons.  If the developer uses this concept effectively, users can create truly dynamic side-by-side comparisons, among other use-cases.

Sheet Isolation

One use-case of QlikView alternate states is to isolate sheets from each other.  There are times (infrequently) when users would want one sheet’s selections to not propagate to the other sheets.  We can simply create a new state in the document and assign the sheet to the new state.  All objects created in that sheet will only respond to selections made in that state and will ignore selections in the default or other states.

Go to Settings –> Document Properties(ctrl-alt-d) –> General –> Alternate States
Select add and then name your new state.

QlikView Alternate States - Creating the states

Now within the sheet properties (ctrl-alt-s), simply pull down the Alternate State drop box and choose the new state.

QlikView Alternate States - Assigning the state
Any objects created within this sheet will by default respond only to selections in this state, thereby isolating this page from the rest of your application.  This really occurs because when an object is created on a sheet it will be assigned the <inherited> state.  This means that the object will simply take on the state of the sheet.
So continuing on with this method, you could conceivably create a QlikView application with several sheets that are all completely isolated from each other.  Simply create a new state for each sheet.

QlikView Comparative Analysis

The second use-case I have found for using Alternate States is when you want to enable a form of Comparative Analysis.  This allows to basically set up two list boxes containing the exact same field, but assigned to two different states.  Then we can create charts that utilize the selections from those states in expressions.  This allows to compare a mix of products against a mix of other products, for example.  This is extremely powerful as you can compare one product to several other products at the same time, or one grouping of products compared to another grouping of products.
The sample application includes two types of expressions to help explain the syntax.

Method 1

The first example on sheet Product Bucket Comparison can be set up by following these steps:
Create two alternate states in Document Properties –> Alternate States.  I called mine Group1 and Group2.  Leave your sheet in the default state for this example.
Create two list boxes using Product_Long as the dimension.  The first list box will be assigned a state of Group1 and the second will be assigned Group2.  Note that when making selections in these boxes, they are not reflected in any other object right now, including the current selections box.

Now create a bar chart in the default state with no dimensions.  We will add two expressions:

      Group 1 Products: SUM({<Product_Long=Group1::Product_Long>}ExtendedAmount)
      Group 2 Products: SUM({<Product_Long=Group2::Product_Long>}ExtendedAmount)
Note the use of set analysis in the expressions above.  We are referencing the alternate states in the suffix of the modifier.  In layman’s terms we are asking QlikView to sum up the extended amount, respecting the default state of selections where Product_Long corresponds to the selections for that field in the Group1 state.  The “::” allow us to reference and separate a state from the field in the set.  This object and the expression still operate in the default state “$” (implied), but will now respect the selection for that field in the other states.
Doing it this way ensures that the other selections on the sheet still operate at a “global” level.  So we can filter down to a specific universal criteria and then make selections in the Product list boxes to get our comparison.
QlikView Comparative Analysis - Example Screenshot

 Method 2

Now we will, in effect, do the same thing but use a different format of expression.  In this second example, the user can select different groups of months and then see the comparisons on the screen.  We could build static set analysis to cover frequent comparisons like this year vs. last ytd, but these dynamic kinds of comparisons would be difficult to achieve without Alternate States.  Using dates in your comparative analysis is a good use-case as I frequently get asked to have the ability to compare this April with February, or April against the prior three months as an example.
Follow the same steps as above.  The only thing that will be different in this example (besides field names and such) will be the syntax in our expressions:
Group 1 Dates:  SUM({Group3<Category=$::Category,ProductLine=$::ProductLine,Product=$::Product,

[Product Num]=$::[Product Num],SubCategory=$::SubCategory,LastName=$::LastName,
Gender=$::Gender,City=$::City,State=$::State,Country=$::Country,Occupation=$::Occupation,
[Home Owner]=$::[Home Owner],NumberCarsOwned=$::NumberCarsOwned,NumberChildrenAtHome=$::NumberChildrenAtHome,
YearlyIncome=$::YearlyIncome>}ExtendedAmount)

The first method would actually still be preferred, but I wanted to show you another way of achieving the same result.  In this case we have assigned the state in the identifier of the set, and then made exceptions for the “global” list boxes on the page.  In this case they will be directed to the selections in the default state for those fields.
QlikView Comparative Analysis - Screenshot example 2
Notice in the straight table we have actually calculated the variance between the two sets in a single expression.  We did this very simply with: (column(1)/column(2))-1

Conclusion

As far as the two methods go, I find the first method to be easier in most cases where we are doing some sort of comparative analysis.  The second would be better if we are disregarding selections in the default state or if there are very few default selections being respected.
Probably the most important thing to remember as a developer is to make sure it is very obvious what the user is supposed to do with these sheets.  Use consistent colors when a group is referenced and include text descriptors to help lead users through the experience.
Several people have written eloquently on this topic:
There are probably other use-cases of QlikView alternate states I have not thought of and definitely much more elaborate examples of this.  I would love to hear about other use-cases for this feature.  Have fun!
1 comment… add one
  • Reply Qinghe February 27, 2017, 3:53 pm

    Thanks a lot for excellent explanation!
    May I ask a question? How can I set a default value for each state when the document is opened?
    For example, when I open the document, it will show comparsion between the product ‘Milk’ with ‘Orange Juice’.
    Thanks,
    Qinghe

Leave a Comment

Join us at Living QlikView

Never miss a post.

We Never Spam. NEVER.

Show Buttons
Hide Buttons