Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Commenting in variables - issue

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?

15 Replies
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

Anonymous
Not applicable
Author

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?


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

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

Anonymous
Not applicable
Author

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.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

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

-Rob

Anonymous
Not applicable
Author

In the variable editor.

The post is related to variables created in the editor.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

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

-Rob

Anonymous
Not applicable
Author

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

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