2 Replies Latest reply: Mar 27, 2018 10:04 AM by Berenice Gonzalez 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:



      + 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



      - 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.