8 Replies Latest reply: May 4, 2016 1:54 AM by Gysbert Wassenaar RSS

    Remove/add rows based on the value of a variable

    Asif Mehedi

      I have a dimension (let's call it dim1) with three values: A, B, and C. There's a button which toggles the value of a variable (let's call the variable vButton) between 0 and 1. This is what I'd like to happen. When vButton is 0, all charts will reflect only the rows associated with A and B in dim1 (as if the rows associated with C didn't exist). When vButton is 1, all rows in the dataset (including the ones associated with C) will be used to populate the chart. Essentially, based on the value of vButton, some rows will be temporarily removed or added back.

       

      I'm new to Qlik and I'm puzzled as to why this seems so difficult to do. I tried set expressions, but that seems to be chart specific. I could probably write set expressions for each chart, but that sounds unnecessarily complicated. How should I go about solving this? Thanks a lot in advance.

        • Re: Remove/add rows based on the value of a variable
          Gysbert Wassenaar

          Instead of a Set Variable action you can use a Toggle Select action and directly toggle the selection of the value C in the field. This is easier than using a variable. But perhaps you want to apply this selection only to one chart. In that case using a variable makes sense. You can use a calculated dimension: =if( $(vButton) =1, if(dim1<>'C' ,dim1), dim1).

          • Re: Remove/add rows based on the value of a variable
            Marcus Sommer

            If you want to avoid hard-coded conditions within the expressions for all these objects you will need to add your logic within the datamodel. This meant to create a flag-field from 0 or 1 to your data which then could be queried within the expressions per set analysis like:

             

            sum({ < Flag = {">=$(vButton)"}>} YourValue)

             

            whereby the 0/1 logic is reversed to your suggestion - which meant that 1 = limited dimension and 0 = all dimension values.

             

            Another possibility which didn't require an expression-condition but more efforts within the datamodel might be the approach from The As-Of Table.

             

            - Marcus

              • Re: Remove/add rows based on the value of a variable
                Asif Mehedi

                Thank you. I'm afraid I'm too new to the Qlik world to follow your explanation.

                you will need to add your logic within the datamodelo. This meant to create a flag-field from 0 or 1 to your data which then could be queried within the expressions per set analysis like:

                 

                sum({ < Flag = {">=$(vButton)"}>} YourValue)

                Could you point me to any documentation to help me better understand how to do that?

                 

                I want all the charts to change with the change in value of the variable. I believe you're suggesting that I use set expressions in each chart's measure. Is that correct? This doesn't sound like an efficient way achieving a global change.

                  • Re: Remove/add rows based on the value of a variable
                    Marcus Sommer

                    The normal and more recommended way to use qlik is to use normal selections and not to involve any macros, actions or variables within them. Of course there are more and enhanced ways to create your usability but the needed know how and the efforts to implement this could become very sophisticated and comprehensive. Therefore try to cover everything with normal selections and use other ways only for this situations where you have special requirements.

                     

                    Let the User Select

                     

                    To get a better unstanding what's meant with flags have a look here: Customized flags.

                     

                    - Marcus