Qlikview Macro Loop through Items in List Box

In Qlikview, there are cases where I need to cycle through a given List Box object, performing actions based on the selected value.  I’ve used this technique to run reports, export data and visually walk an audience through changes in a chart based on the selected item.  In the following post, I will provide a very simple example of how to set this up using a Qlikview macro.  The code will simply identify all the possible selections (GetPossibleValues) in a given List Box, then loop through each and display the value in a message box.  I will also demonstrate how to loop through the alternative values (GetAlternativeValues), based on the selected value in the List Box.

Setup

Once you have identified a List Box (in my example, I am using a List Box assigned to field “Teams”), go into Tools –> Edit Module, and add the following Sub routines:

Make sure you check the following settings in the Edit Module window:

Qlikview

Next, add two Button objects next to your List Box, and assign each macro above (LoopItems & LoopAlternativeItems) to these Buttons.  In the Button object properties under the “Actions” tab, select the “External – Run Macro” action

Qlikview

Then, assign the respective macro to the action:

QlikviewMacroLoopItemsListBox

Repeat the steps above on the second button, adding an action to run the macro “LoopAlternativeItems”.  Once you are finished with the setup, your objects should look something like this:

QlikviewMacroLoopItemsListBox

If you click on the “Loop Teams” button, you will see a message box appear:

QlikviewMacroLoopItemsListBox

This is the first item in the “Team” List Box object.  Continue hitting OK on each message box and you will get a separate message box for each item in the List Box (in my example, 14 total).  These are the Possible values in the List Box object (those items currently selected).  If you have no selected values, the macro will loop through all the possible values.  This macro uses the “GetPossibleValues” method.

Now, say you have the following items selected in the List Box object:

QlikviewMacroLoopItemsListBox

If you click on the “Loop Alternative Teams” button, you will see two message boxes appear, one for item “Nebraska Cornhuskers” and a second for “Wisconsin Badgers”.  These are the Alternative values in the List Box object (those not currently selected in the screen shot above).  This uses the “GetAlternativeValues” method.

QlikviewMacroLoopItemsListBox

 

Additional Content

Check out more examples by visiting my Home Page

Here you will find topics covering  Qlikview  SQL Server  Excel VBA

 

 

Leave a Comment