How to Set a QlikView Variable to a Specific Value Using Filters

    Use NPrinting filters to set the value of a variable in a QlikView document. This tutorial uses SalesDemo.qvw

    You need to create the required variables in your QlikView application and refresh the objects list before starting this tutorial.

            

    Begin Creating New Excel Report

                      
                Begin-Creating-New-Excel-Report.png                  
            
    1. Select Reports in the lower left pane
    2. Select Excel reports in the upper left pane
    3. Click on Excel Report in the New group of the tool bar
          
          
          
            

    Identify New Report

                      
                Identify-New-Report.png                  
            
    1. Enter Set QlikView Variable Value with Filters as report Name
    2. Enter a clarifying Description if need be (optional)
          
          
          
            

    Begin Creating New Filter

                      
                Begin-Creating-New-Filter.png                  
            
    1. Click on the Filters icon in the Show group of the tool bar
    2. Click on the New icon in the Filters group of the tool bar
          
          
          
            

    Identify Filter

                      
                Identify-Filter.png                  
            
    1. Enter Set vLast Year to 2013 and vCurrentYear to 2014 as filter Name
    2. Enter a clarifying Description if need be (optional)
          
          
          
            

    Open Variable Configuration Window

                      
                Open-Variable-Configuration-Window.png                  
            
    1. Select the Variables icon in the Show group of the tool bar
    2. Click on the Add icon in the Variables group of the tool bar
          
          
          
            

    Open Select Variable Window

                      
                Open-Select-Variable-Window.png                  
            

    Click on the browse button at the extreme right of the Name field in the Variable window

          
          
          
            

    Select Variable

                      
                Select-Variable.png                  
            
    1. Select the Connection to the QlikView document that contains the Variable you want
    2. Select the vLastYear variable
    3. Click on the OK button
          
          
          
            

    Set Variable Value

                      
                Set-Variable-Value.png                  
            
    1. Enter 2013 in the Value field
    2. Put a check mark in the Calculate box only if you enter a formula in the Value field, as it will need to be evaluated by QlikView. A constant has been entered here, so leave the Calculate box unchecked
    3. Click on the OK button
          
          
          
            

    Add Another Variable

                      
                Add-Another-Variable.png                  
            
    1. Click on the Add icon again
    2. Click on the browse button again
          
          
          
            

    Set Another Variable Value

                      
                Set-Another-Variable-Value.png                  
            
    1. Select the Connection to the QlikView document that contains the Variable you want
    2. Select the vCurrentYear variable
    3. Click on the OK button
          
          
          
            

    Set vCurrentYear to 2014

                      
                Set-vCurrentYear-to-2014.png                  
            
    1. Enter 2014 in the Value field
    2. Click on the OK button
          
          
          
            

    Save Filters

                      
                Save-Filters.png                  
            

    Click on the Save and Close icon in the Actions group.

          
          
          
            

    Open New Template in Template Editor

                      
                Open-New-Template-in-Template-Editor.png                  
            

    Click on New in the Template group of the tool bar.

          
          
          
            

    Open "Save template as..." Window

                      
                Open--Save-template-as--Window.png                  
            

    Click on the Save As icon in the Actions group.

          
          
          
            

    Save Template

                      
                Save-Template.png                  
            
    1. Make sure the Save template as... window has opened in the C:\NPrintingTraining\Templates\ folder. If not, browse to it.
    2. Enter a File name or accept the suggested one
    3. Click on the Save button
          
          
          
            

    Open Select Objects Window

                      
                Open-Select-Objects-Window.png                  
            
    1. Right click on the Tables node
    2. Click on the Add objects button
          
          
          
            

    Select Object to Embed as Table

                      
                Select-Object-to-Embed-as-Table.png                  
            
    1. Select the Connection to the QlikView document that contains the object to be added as a table
    2. Select the Sales over Time by Category - CH251 object
    3. Click on the OK button
          
          
          
            

    Open Select Variables Window

                      
                Open-Select-Variables-Window.png                  
            
    1. Right click on the Variables node
    2. Click on the Add variables button
          
          
          
            

    Select Variables to Be Added

                      
                Select-Variables-to-Be-Added.png                  
            
    1. Select the Connection to the QlikView document that contains the object(s) to be added as a table
    2. Select the vCurrentYear and vLastYear objects from the SalesDemo connection.

    Repeat 1. and 2. as necessary

    1. Click on the OK button
          
          
          
            

    Add Headings to and Embed Variables in Template

                      
                   Add-Headings-to-and-Embed-Variables-in-Template.png            
            
    1. Enter the headings Last Year and Current Year into cells A1 and B1 respectively
    2. Drag the variables vLastYear and vCurrentYear and drop them onto cells A2 and B2 respectively
          
          
          
            

    Embed Table Columns in Template

                      
                Embed-Table-Columns-in-Template.png                  
            
    1. Expand the CH251 - Sales over Time by Category node by clicking on the '+' to its left
    2. Drag the Category Name, =$(vLastYear), and =$(vCurrentYear) node tokens into the template and drop them onto cells B4, C4, and D4 respectively
          
          
          
            

    Change Headings

                      
                Change-Headings.png                  
            

    Substitute the =$(vLastYear), and =$(vCurrentYear) headings with =B1 and =B2 respectively.

          
          
          
            

    Apply Formatting

                      
                Apply-Formatting.png                  
            

    Use Excel formatting tools to format headings and data.

          
          
          
            

    Run Preview

                      
                Run-Preview.png                  
            

    Click on the upper part of the Preview icon in the Actions group of the tool bar.

          
          
          
            

    Inspect Results

                      
                Inspect-Results.png                  
            

    You will see the data for 2013 and 2014 regardless of the year in which you launch the preview.

          
          
          
            

    Save Your Work in Template and Close Template Editor

                      
                Save-Your-Work-in-Template-and-Close-Template-Edit.png                  
            

    Click on the Save and Close icon in the Actions group.

          
          
          
            

    Save and Close Report

                      
                Save-and-Close-Report.png                  
            

    Click on the Save and Close icon in the Actions group.