2 Replies Latest reply: Jun 24, 2011 1:15 AM by AXON SG RSS

    enabling/disabling expressions based on selections

      hi guys, let's say i have a bar chart and a list box with sales, costs and netrevenue as its selections

       

      the chart shows sales, costs and netrevenue as its expressions with location as the dimension

       

      by default all 3 bars will be shown. whenever i select only sales from the list box, only the sales bar will be enabled and the rest disabled and whenever i select sales and costs, only the sales bar and costs bar will appear...

       

      through some searching, it seems that i can do some coding/macro to enable/disable the expressions based on the list box's selection

       

      how do i go about doing that for my case?

        • Re: enabling/disabling expressions based on selections
          Angus Monro

          You could do it with coding / macros.  The coding/macro approach would

          be something like

           

          1.     create MeasureName as an artificial dimension (i.e. create a

          table in your script that has MeasureName as its only field, and

          populate it with the 3 values via INLINE)

          2.     create a variable for each Measure that tests if that Measure is

          selected or possible (e.g. vSalesIsSelected), using

          GetFieldSelections(). Make sure the expression has '=' on the front of

          it. 

          3.     in your chart, create the expression for Sales as something like

          if(vSalesIsSelected,calculation), so that the expression is always null

          when Sales isn't selected (and hence QlikView won't display it).

          Similarly define the expressions for the other two measures.

           

          An alternative approach is to design your data model so that the

          appropriate table has

           

          *     

               a field called MeasureName (which can have values 'Sales','Cost'

          or 'Net Revenue') and

          *     

               a field called MeasureValue, giving the value of Sales, Cost or

          Net Revenue as required.

           

          Then, your list box shows MeasureName, and your chart has MeasureName as

          one of the dimensions.  This avoids the messiness of variables & extra

          expressions - at the cost of possibly changing your data model.  Pros &

          cons!

           

           

          Angus.

            • Re: enabling/disabling expressions based on selections

              hi Angus thanks for your reply,

               

              what if i wanna do it like what i've described in another discussion http://community.qlik.com/thread/30437

               

              i will have 2 list boxes, 1 list box with the location field and 1 list box with sales, costs and netrevenue

               

              as described in that discussion, sales/costs/netrevenue will be the dimensions

               

              and assuming i have location1 location2 and location3 under the field location

               

              by default there would be 3 sets of bars (sales, costs and netrevenue) and each set of bars will 3 bars that are location-specific...

               

              if i only selected sales and costs, there would only be 2 sets of bars, each set having 3 location bars since i did not specifically select the location to look at

               

              if i only selected sales, there would only be 1 set of bars n the set having 3 location bars since again i did not specifically select the location to look at

               

              if i only selected sales, location2 and location3, there would again be only 1 set of bars. however, this set of bars will only have 2 bars since i only selected 2 locations

               

              sales/costs/netrevenue/location are currently 4 fields in my table...