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

Using a variable in set analysis

I have set a Current Month variable:

vCurrentMonth= Month(Today(2));

Which works in a text object, it shows "Jun" which is what I am looking for.

The expression I use the variable in is as follows:

=Count( {$< EndMonth =  { '$(vCurrentMonth)' } >} [Assignment ID] )

Which results in zeros. But if I type Jun in place of the variable I get the correct data.

I've tried:

=Count( {$< EndMonth = { '=$(vCurrentMonth)' } >} [Assignment ID] )        Shows all data as if there was no set analysis

=Count( {$< EndMonth = { ='$(vCurrentMonth)' } >} [Assignment ID] )        null values

=Count( {$< EndMonth = { $('vCurrentMonth') } >} [Assignment ID] )          null values

=Count( {$< EndMonth = { "$(vCurrentMonth)" } >} [Assignment ID] )         null values


I'm all out of ideas for why this isn't working. Can anyone see a mistake in the syntax or have any insight for why this variable is not working.


Thanks,

1 Solution

Accepted Solutions
jerem1234
Specialist II
Specialist II

You'll want to use the keyword LET in your script:

LET vCurrentMonth= Month(Today(2));


This will put the value 'Jun" into your variable. Then your formula:


=Count( {$< EndMonth =  {$(vCurrentMonth)} >} [Assignment ID] )


will work. Then you can just have the formula for your textbox be:


=vCurrentMonth


Hope this helps!

View solution in original post

7 Replies
jerem1234
Specialist II
Specialist II

try:


Count( {$< EndMonth = { '$(=vCurrentMonth)' } >} [Assignment ID] )


Hope this helps!

maxgro
MVP
MVP

this

=count({$ <Month={'$(vCurrentMonth)'}>} [Assignment ID] )

and this

=count({$ <Month={$(vCurrentMonth)}>} [Assignment ID] )

should work

is your variable (ctrl+alt+v)

=Month(Today(2))

or

Month(Today(2))

?

jerem1234
Specialist II
Specialist II

Here's another one you can try:

Count( {$< EndMonth = {'$(=$(vCurrentMonth)) } >} [Assignment ID] )


As Massimo Grossi brings up, having or not having the equal sign in the declaration of the variable will affect your expression. The above should work if it does not have the equal sign. The others listed should work if it has the equal sign

Not applicable
Author

The variable does not include the equal sign.

The script: SET vCurrentMonth= Month(Today(2));

Is it best practice to include the equal sign as well?

example: SET vCurrentMonth= =Month(Today(2));

Not applicable
Author

Your answer works and, as you said, Massimo's answer works if I change the variable to have an equal sign.

SET vCurrentMonth= =Month(Today(2));

However once I add the value sign my text object no longer displays the data.

Expression: =$(vCurrentMonth)

It used to display Jun, now it produces a null value "-"

jerem1234
Specialist II
Specialist II

You'll want to use the keyword LET in your script:

LET vCurrentMonth= Month(Today(2));


This will put the value 'Jun" into your variable. Then your formula:


=Count( {$< EndMonth =  {$(vCurrentMonth)} >} [Assignment ID] )


will work. Then you can just have the formula for your textbox be:


=vCurrentMonth


Hope this helps!

ZoeM
Specialist
Specialist

Super Awesome. I was so baffled as to why my text entry was not working lol. Thanks for the help