15 Replies Latest reply: Nov 22, 2017 11:03 AM by Grzegorz Smajdor RSS

    Commenting in variables - issue

    Grzegorz Smajdor

      Hi,

       

      I think I found commenting issue in variables.

      Let's try to create two variables:

       

      vOne

      =2+ count(

      sth)

      //comment

       

      vTwo

      =1

       

      Now try to add $(vOne)+$(vTwo).  Let's assume that count(sth) returns 10.

      The result should be 13.

      But it's 12.

       

      It's seems that comment in variable deactivate or clears everything after this comment. (in this case clears the "vTwo" variable)

       

      Is this intended? Or another issue with Qlik's syntax?

        • Re: Commenting in variables - issue
          Marcus Sommer

          I would say it's intended and worked as designed. It meant you need to be careful how and where to use comments:

           

          Well-commented variables. Be careful!

           

          - Marcus

            • Re: Commenting in variables - issue
              Grzegorz Smajdor

              The mentioned doc is related to Qlik VIEW, not Qlik Sense.

              What is more, the doc is posted by 'typical' user, it's not official.

               

              I've tried to find this topic in official help and articles, but there is nothing about commenting in variables.

              Any ideas?


                • Re: Commenting in variables - issue
                  Marcus Sommer

                  QlikView and Qlik Sense are in many things the very same, for example the script and the behaviour of variables. You are right, the official documenting of features isn't the most strengths of Qlik but the community over compensate many of them with very practically examples.

                   

                  In this case variables aren't treated different to the normal script respectively expression (variables are just a replacement for text) so that comments are not specially mentioned by variables else the explaining of comments is also valid for them: https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/LoadData/comment-in-script.htm.

                   

                  This meant if you really want to use comments within variables you need to be careful with the starting/ending of variables and line-breaks. In your example from above you could use the following:

                   

                  =2+ count(

                  sth)

                  /* comment */

                   

                  - Marcus

                    • Re: Commenting in variables - issue
                      Grzegorz Smajdor

                      Thanks Marcus. As you can see there is a lack of documentation for some topics.

                       

                      To the point - I've tested some different solutions and found an interesting example.

                       

                      Let's modify vTwo

                      vTwo

                      =1

                      +2

                       

                      variable vOne is still the same

                      vOne

                      =2+ count(

                      sth)

                      //comment

                       

                      According to the posts above - variables are replacements of text.

                      So $(vOne)+$(vTwo) should return:

                      2+ count(

                      sth)

                      //comment 1

                      +2

                       

                      This //comment will deactivate "1" but should has no impact on the "+2" (+2 is in a new line, and // deactivates only text in one line)

                      It should add 2 + count(sth) + 2.

                       

                      I've tested it and //commment deactivates everything in vTwo, also "+2" in new line.

                      That means something is wrong here.

                      It is not just a replacement of text.

                        • Re: Commenting in variables - issue
                          Rob Wunderlich

                          Where are you typing the // comment?  In the script or the variable editor?

                           

                          -Rob

                            • Re: Commenting in variables - issue
                              Grzegorz Smajdor

                              In the variable editor.

                              The post is related to variables created in the editor.

                                • Re: Commenting in variables - issue
                                  Rob Wunderlich

                                  Curious, in what case would you type a // comment in a variable definition as opposed to using the description field?

                                   

                                  -Rob

                                    • Re: Commenting in variables - issue
                                      Grzegorz Smajdor

                                      - because switching between the "Edit expression" window and the variable editor/overview window is annoying?

                                      - to keep everything (formulas and notes) in one place?

                                      - because that is the purpose of a comment (to use it)?

                                       

                                       

                                      Btw Rob, I think your question doesn't bring users closer to the objective.

                                        • Re: Commenting in variables - issue
                                          Marcus Sommer

                                          I agree that there is some space for improvements by the variable-handling including adding and viewing of comments but even if I repeat myself the variable-content is a rather unsuitable place for it and is rather uncommon in the most scripting/programming-tools.

                                           

                                          If you really want to keep everything in one place you will need to use external sources - a central repository - for it. Of course this is possible and had some advantages, too but the efforts to implement a stable solution will be quite expensive.

                                           

                                          Beside them I personally don't need very often to look within the variable-editor because I do usually use variables only there where it really simplified my (developer) live. A massive use of variables could be lead to quite the opposite ...

                                           

                                          - Marcus

                                          • Re: Commenting in variables - issue
                                            Rob Wunderlich

                                            I'm working on some variable tooling and I am just trying to understand the various ways people use variables. I don't have an opinion on your original question beyond what Marcus has suggested.

                                             

                                            -Rob

                                        • Re: Commenting in variables - issue
                                          Marcus Sommer

                                          I think Rob is right you should use the description field of the variable if you want to comment their content.

                                           

                                          Using variables in Qlik is in general quite easy but you need to be careful where and how you defined the variables - either script or editor and either with leading equal sign or not respectively the script-versions to them of LET or SET. Further important is which type of content a variable has and where and how they will be called.

                                           

                                          This sounds now a bit complex but there are only a few clear rules and the possibility to differ between above mentioned features is a strength and not a bug. By combining several variables within an expression or even using parametrized variables you could easily add a complexity which is hard to understand unless you separate each part of them and looks what really happens in them.

                                           

                                          In this sense commentings within variables are just error-prone and you should avoid them.

                                           

                                          In your example the important fact is that vTwo starts with an equal-sign and contains therefore the value of 3. The various differences between using the = at the beginning and the use of $-expansion by calling them could you check within some textboxes or maybe a table like:

                                           

                                          More backgrounds could you find here: Variables

                                           

                                          - Marcus

                                            • Re: Commenting in variables - issue
                                              Grzegorz Smajdor

                                              I think you lost the point of the discussion.

                                              It's not about using $-expression, it's not about let/set choice, it's not about which place is better for description etc.

                                               

                                              The problem is following:

                                              Qlik Sense allows us to create and define variables in the "variable editor".

                                              QS allows us to comment their content.

                                              But this solution seems to be not working properly. It can crush your work.

                                              The point was to investigate if this is an unexpected issue. And I think we found the answer.

                                               

                                              btw

                                              "In this sense commentings within variables are just error-prone and you should avoid them."

                                              If something has been implemented by QS - it should work.

                                              If there is a problem - solve it, do not avoid. [petition for QS Team]

                                                • Re: Commenting in variables - issue
                                                  Marcus Sommer

                                                  Sorry, but I could not agree with you. Of course you could comment variables within their content but you need to consider various things (already mentioned above) by doing it and I think in your example it's not done properly.

                                                   

                                                  From my point of view it worked like it should (although various improvements would be much appreciated). Maybe hic could shed some lights on it.

                                                   

                                                  - Marcus

                                  • Re: Commenting in variables - issue
                                    Mark Little

                                    Just tried this on mine and works fine.

                                    I.E. the comment is compeltely ignored by the calculation.

                                     

                                    Are you running the latest version of Qlik Sense?

                                     

                                    Mark