Saturday, September 19, 2015

Alternate States in QlikView

QVNewbie#4 : Alternate States in QlikView :


Few days ago i was asked to create a basket analysis to compare set of products Vs other Set of products. Yes ,1st thing that strike my mind was Alternate States. . Alternate states are one of the powerful feature to disconnect your set of objects/ sheets from Datamodel. Let's discuss about creating alternate states and various use in this post.


How to Create Alternate State : 

Go to Settings >> Document Properties >> General >> Alternate States… >> Add >> New State Name


Note : Alternate States are called as State Identifiers.




Yes, Now the Alternate State is ready to use, Developer have access to create unlimited Alternate States (State Identifiers).


There are two type of state in Alternate State :


                       1) Default    : Default State is Nothing but the Current Selection $
                       2) Inherited : Inherited is the state which inherits the properties from the parent Document/Sheet/Object. i.e if it is Sheet, It get the state from Document, if it is object, it inherits the properties from Sheet / container. Sheet / object always set to inherit in new document.


Scenario 1 - Assign Alternate to Sheet : If alternate State is assigned to Sheet, the objects available within the sheet will inherit Sheet`s state.


To Assign Alternate State to any Sheet or object , Right Click on the object or sheet on which you`d like to set Alternate State >> Go to Properties >> General >> Alternate State >> Select the State




For Example if State identifier State1 is assigned to sheet, then the objects within the sheet will respond to State1 Alternate State. Object State within the sheet can be also overridden by changing it to the different State Identifier.


Scenario 2 - Alternate State in Expressions :  Let's see how to use the alternate state in expressions.


To illustrate the Alternate State in Expression,Will create a sample data with three fields (Invoice_Date, Order_Type and Region). Now Let's set the Sheet`s Alternate State to inherited which is Default state of the Sheet and Will Assign State1 to Invoice_date List box.


Expression 1 :  Count (ORDER_TYPE)
- Count of Order type is a Simple Exporession which is Current Selstion State. So Selection in Invoice_Date field will not affect the count of this expression as Invoice_date is set to State 1.


Expression 2 :  Count ({State1} ORDER_TYPE)
- Count of Order type, This expression will respond to the selections in Invoice Date field where the State1 State Identifier is Assigned.


Expression 3: Above Expression will respond to the object selections which are within State1 State identifier. However, can we make the above expression respond to the current Selection? Yes It is possible. For example, if i have Field called region in my data model which is in default State ($), Now we wanted this region field selection also to be included in above Expression.


This can be achieved by including the current selection as shown below.


Count ({State1<Region = $::Region>} ORDER_TYPE)


$ sign in the above expression, denotes the Current Selection State, the Simple expansion of the above Expression is Region field from current Selection state (one which is highlighted in pink) is Equated to the Region field in State1  (text which is highlighted in red). Current Selection ($) state can be replace with any other states available in Document.


This Expression can be reversed as below to set the Expression to work in Current Selection ($) state and one or more field from other state can be used within the Expression


Count ({$<Region = State1::Region>} ORDER_TYPE)


Expansion of the above Expression is, overall Expression is set to Current Selection State (one which is highlighted in pink) and Region field from State1 will be equated to Region field in ($) (One which has been Highlighted in Red)


Scenario 3 - Alternate State in Bookmark : Bookmarks capture selections in all states defined in the QlikView document. When recalling a bookmark created in version 11 (or later) the selections in all states will be applied.


For Example if the bookmark is created with the name ‘BookMark1’ with few selections in State1 and Current Selections, This can be used as below


Count ({$<State1::BookMark1>} ORDER_TYPE)


Few other Expressions using Alternate State :

To get the Selected count of field of a particular state,

GetSelectedCount(Invoice_date, ';', ,'State1')

To concatenate field of particular state,

Concat({State1} Chr(39)&Invoice_Date&Chr(39),',')


To find the Alternate State of the Sheet / object  : Statename()


Clear Specific State Selections : Selections on the specific Alternate Selection can be cleared by selecting the Arrow next to Clear Button from the top menu >> Clear Specific State >> State Identifier




Word of Caution : Alternate States might confuse users if this has not been used properly or Documented properly in dashboard.


Hope this helps. Thanks for reading the post and Happy Qliking !!!

No comments:

Post a Comment