Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
mmarchese
Creator II
Creator II

variables vs measures; best practices?

As far as I can tell, variables and master measures in Qlik Sense each have significant pros and cons:

Measures

+ Can be renamed

+ Can be assigned a color

+ Are linked to labels shown in visualizations

- Only have a single name attribute, making it impossible to have both nice-looking labels and an organized list of measures at the same time

- Can't be used inside other measures or inside expressions

- Can't be managed in the data load editor script

Variables

- Can't be renamed

- Can't be assigned a color

- Can't be linked to labels shown in visualizations

- Can't be applied to visualizations as quickly or easily

+ Can be used inside measures, expressions, and other variables

+ Can be managed in the data load editor script

- Awkward to delete if managed in the script since you have to remember to delete it in the worksheet interface too

What to do?

If measures' cons were addressed, variables wouldn't really be needed at all in the worksheet interface, right?  But since I don't know when or if that will happen, I am wondering about current best practices.

It seems to me that any measure I make has a high probability of being needed in another measure or in an expression.  Therefore, I might as well make a variable for every expression I use, and then create measures that point to those variables as needed.

When measures are called for is another good question.  As far as I can tell, the only time measures are truly necessary is when you need to control the coloring of a visualization, since QS somehow has no other way to do this except for some awkward hacks.  But measures do save you from having to repeatedly specify pretty labels and they do make name changes much easier, so they should probably be used quite often instead of using variables directly.

I am thinking that in my script, I will have a Variables section, with a bunch of statements like this:

Set v_uptime = "Sum({<Status={'Running'}>} m_minutes)";

And then, where appropriate, I will have a corresponding measure called Uptime with a definition that is simply $(v_uptime).


That will give me two sets of data containers to manage, but since the measures are just wrappers around variables, it will be easy to deal with.  All expressions will exist in one centralized place, and will be a place that facilitates bulk changes, copying and pasting, etc.  At the same time, I won't have to give up the benefits of measures.


  1. Does this scheme sound reasonable?
  2. What have I failed to consider?
  3. Are there any plans to fix any of the weaknesses I mentioned?
  4. I haven't even considered the best way to handle dimensions yet... feel free to address that as well -- or not.
2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think most people have arrived at the scheme you propose.  That way you get the best of both.

-Rob

http://masterssummit.com

http://qlikviewcookbook.com

bernice_gonzale
Partner - Contributor II
Partner - Contributor II

I'm looking to make the change and move the measures to variables.

What about security? If we have all the variables in a excel file, where this file should reside? How I prevent a user to delete or modify the file?

What is the best practice on this, if I distribute the application to customers.?

Thank you for your help.