8 Replies Latest reply: Dec 8, 2015 7:14 AM by Tahir Khalil RSS

    Set variable with Button Object not working

      I've created two Calendar Objects; one for Start Date that sets a vairable called "vStartDate" and one for End Date that sets a variable called "vEndDate".  When I change the date through the Calendar Object I am able to change the range in my chart as my Expression has the following defininition:

       

      ( if( DATA_TS >= $(vStartDate) AND DATA_TS <= $(vEndDate), DISKAVG))

       

       

      This functionality works perfect. To take things a step further, now I am adding some Button Objects as shortcuts to give me specific ranges, i.e. last 7 days, Just October, etc.  I assumed I could just assign Actions of Set Variable in the Button Objects to accomplish this goal.  What I'm seeing is that the variables are indeed getting set, as my Calendar Objects display the new values, but the chart is not using the set values, instead it seems to be failing as the chart goes blank with message "No data to display".  Any and all advice here is appreciated as I am quite new to Qlikview.

        • Re: Set variable with Button Object not working
          Stefan Wühl

          Lew,

           

          I would also think that the approach should essentially work out.

           

          I think you need to recheck the format of your variables, as you set them in the button actions.

           

          You can check this by looking at the values in variable overview, or maybe try:

           

          =' ( if( DATA_TS >= $(vStartDate) AND DATA_TS <= $(vEndDate), DISKAVG)) '

           

          as expression in a text box. What do you see?

           

          If possible, you could also upload also a small sample qvw to the forum (upload available in advanced editor).

           

          Regards,

          Stefan

            • Re: Set variable with Button Object not working

              Stefan,

               

              Thanks for your help here.  This was indeed a case of the variable data being saved in wrong format by the Button.

              I had to change the Value expression in the button for vEndDate from

               

              =Max(DATA_TS)

               

              To:

               

              =Max(DATA_TS)-0

               

              Seems adding the -0 converts the timestamp to a decimal number.  I figured this out as the value for the vStartDate was being set properly for my "-7 for 7" button -- its expression is: =Max(DATA_TS)-7.

               

              Thanks for your help and quick response!

               

              Regards,

              Lew

                • Re: Set variable with Button Object not working

                  Just became aware of a related problem. Calendar and Buttons are now setting start and end dates correctly and have confirmed they are being utilized by my chart.  Problem now is a Table Box that lists the applicable data does not seem to get updated to reflect the selected range, i.e. DATA_TS column shows all dates.  Is there a way to insure my Table Box will get filtered by my new range?  Basically I need DATE_TS to inherit the selection values of my variables. To clarify, if I select my button for a specific date or date range, the values from the variables should become my current selection for DATA_TS.

                    • Re: Set variable with Button Object not working
                      Stefan Wühl

                      Lew,

                       

                      a table box just shows the possible set of records in your current selection, you can't define calculated dimensions or expressions for a table box.

                       

                      And actually you are not doing a selection when you are assigning values to variables and use these in a calculated dimension or expression (that's just another way to filter data, but only in the scope of that object, while a selection is affecting all objects in that state.

                       

                      So if you want your table box and all other objects to be limited to your date selection as well, you need to perform a selection in DATA_TS using the variables. You can use a button action to perform this, I think there should be plenty of samples around in this forum on how to build the correct search expression in this action (this could be a bit tricky).

                       

                      Stefan

                        • Re: Set variable with Button Object not working

                          Hello Stefan,

                           

                          As I'm new to Qlikview I'm sure my questions are quite elementary at this point, so thank you for entertaining them. I sort of came to same conclusion you are explaining above.  Seems setting variables as my action in the Buttons is not the right way to go if I want to effect the actual current selected for my DATA_TS field.  It seems I need to use a 'Select in Field' Action as opposed to a 'Set Variable' Action.

                           

                          I was able to get my "Latest" Button working using two 'Select in Field' Actions.  The first one sets field DATA_TS, to Search String =(vMaxDate), where vMax_Date is a variable set at reload to the Max(DATA_TS). The second 'Select in Field' just has an expression in Field of =DATE(MAX(DATA_TS)-0), nothing in Search String.

                           

                          I was able to get my "Prior Day" Button working using a 'Select in Field" Action where Field is DATA_TS, and Search String is =DATA(Max(DATA_TS)-1).

                           

                          What I can't seem to figure out is how to assign DATA_TS a range of values in a Button, which I would require for my "-7 Days for 7" and "-14 Days for 7", etc. Buttons? 

                           

                          Any thoughts?

                           

                          Best Regards,

                          Lew

                  • Re: Set variable with Button Object not working
                    Tahir Khalil

                    I have the same issue.

                     

                    I am using the variable to filter out Store_Code field.

                     

                    =if(SOS_YesAnswers<$(VariableX1) OR SS_YesAnswers<$(VariableX1) OR Pr_YesAnswers<$(VariableX1), Store_Code)

                     

                    The definition of VariableX1 is

                    =Pick(Match(StoreTypeGroup,'Cosmetic Store','Rural','FamilyGrocer','General Bakers','Interface','MKD','Supermarket-GT'), Var1,Var2,Var3,Var4,Var5,Var6,Var7)

                     

                    Var1...Var7 contain numbers.

                     

                    I am using SET IN FIELD with action as

                     

                    ='=if(SOS_YesAnswers>=$(VariableX1) and SS_YesAnswers>=$(VariableX1) and Pr_YesAnswers>=$(VariableX1), Store_Code)'

                     

                    But this is not applying any filter - If I use a Column in place of $(VariableX1) - it is working fine. I am able to use the VariableX1 in different tables/charts.

                     

                    Any clue?