1 Reply Latest reply: May 9, 2017 12:58 AM by Rob Wunderlich RSS

    variables vs measures; best practices?

    Michael Marchese

      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 vUptime = "Sum({<Status={'Running'}>} m.Minutes)";

       

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


      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.