2 Replies Latest reply: Mar 26, 2017 3:50 PM by Andy Weir

# QlikSense Variable VS MasterItem

Hi Guys,

could you list the main difference between master item and variables.

Regards

• ###### Re: QlikSense Variable VS MasterItem

Hi Ahmed,

Let me explain the differences and to be more practical, the difference uses of each option:

1) Master item (master measure for example),when and why we use a master measure?

Suppose we have a measure: sum(Sales) that we used in 1 graphic, then another one, then a 3rd one..

After a while, it became clear that the use of this particular measure will be frequent.

What to do in this case? Will we rewrite each time? 20 times? NO !

In this case It's an easy expression, what if it was kind of a more complicated one?

Example: sum({<Year={"\$(=(Max(Year)-2))"}>}Sales) : (sum of sales for the 3 last years (depends on our selection of the year).

In this case, and if we knew that the use of this expression will be frequent, we write it ONLY ONCE.

We create it as a master measure, and call it in each graphic.

And notice, when we create a master item, it will appear in the first lines when we wanna choose a measure(or dimension). Thus, It's really easy to find and use:

2) Variables, the use of variables in the other hand can serve in so many cases; but let's focus on a scenario that ressembles the one above:

So our expression is:

sum({<Year={"\$(=(Max(Year)-2))"}>}Sales)

Now, what if I wanna see sum(Sales) , count(Magasins), sum(Marge) , count(transactions) and so on for the last 3 years.

What to do?

We can create 4 master measures as seen above, but ALSO we can use a variable in which we put the part "of the 3 last years"

In other words: we create a variable called vLast3Years for example =Year={"\$(=(Max(Year)-2))"}

and this way, we can just call this variable in our expressions:

sum({<\$(vLast3Years)>}Sales)

sum({<\$(vLast3Years)>}Marge)

count({<\$(vLast3Years)>}Magasins)

count{<\$(vLast3Years)>}transactions)

Why doing so? Let's assume, that we want to have: sum(Sales) for the last 3 years in one graph, and sum sales for the last 3 years for only Country=Tunisia in the other graph,

With a master measure: we should create another expressions for Tunisia:

sum({<Year={"\$(=(Max(Year)-2))"}, Country={'Tunisia'}>}Sales)

And then, we call this new measure in the other graphic because with master measure, we can't edit it in a single graphic. If you alter the measure for one graphic, use must alter the original master measure, and it will change in all the graphics using it !

In the other hand,with variables, things are more flexible.

As you see, we only created a variable = vLast3Years.

Now, if you wanna change the original expression sum({<\$(vLast3Years)>}Sales) in a particular grphic, we can do it directly : sum({<\$(vLast3Years) , Country={'Tunisia'}>}Sales)

That's one use, we can use variables in so much cases to make our dashboard dynamic and richer !

Hope this helps?

Omar,

• ###### Re: QlikSense Variable VS MasterItem

Both are great ways to define things you need to use regularly in your dashboard.

The current benefit of variables for me is

1, I can store my definitions outside of qlik which can be useful when wanting to migrate things easily from one environment to another.

2. You can reference a variable in my load scripts and other expressions or master items you cannot reference a master item the other way.

The benefit of master items

1. I can expose these repeatable measures? Dimensions and visualizations to my end users to use confident that they can use some complex functions safely without being exposed to the underlying set analysis.

2. Can't store a visualization as a variable.

So for me they do similar things but variables are for power users/ developers and master items for business users.