Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

gsmajdor
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
Not applicable

Re: Commenting in variables - issue

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

gsmajdor
Not applicable

Re: Commenting in variables - issue

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
Not applicable

Re: Commenting in variables - issue

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

gsmajdor
Not applicable

Re: Commenting in variables - issue

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
Not applicable

Re: Commenting in variables - issue

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

-Rob

gsmajdor
Not applicable

Re: Commenting in variables - issue

In the variable editor.

The post is related to variables created in the editor.

rwunderlich
Not applicable

Re: Commenting in variables - issue

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

-Rob

gsmajdor
Not applicable

Re: Commenting in variables - issue

- 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
Not applicable

Re: Commenting in variables - issue

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