Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
bashar_f
Partner - Creator
Partner - Creator

How to create a variable based on another variable

Hello,

I have 2 variables vCurrentYear & vPreviousYear

vCurrentYear = right (year(today()),2)

because I only want it to get '14'

vPreviousYear =$(vCurrentYear)-1

which will give me 13

Now, I want to create a new variable that will check a part of a field to see if its the current year or the previous year

I have a semester field which is filled like 1401, 1402, 1301, 1302

the 14 and 13 being the year.

now what I put into the variable was this

Count( {<(Left(Semester,2))=($vPreviousYear)>}EMPLID)

meaning count all the EMPLID where the first two digits of the semester field are equal to the Previous year which 13.

It won't work, I think it has to do with the syntax, some help please.

Labels (1)
1 Solution

Accepted Solutions
Not applicable

You can also keep your variables as you declared them initially and try the below:

count({<Semester={"=Left(Semester, 2) = $(vPreviousYear)"}>} EMPLID)

View solution in original post

6 Replies
simondachstr
Specialist III
Specialist III

That's a tricky one. For now I found a small workaround modifying the vPreviousYear variable to 14*, 13* respectively.

13* in the set modifier does the same like using the left() function on the field (Which is not possible).

See attached.

Anonymous
Not applicable

I noticed a missing backet.

Count( {<(Left(Semester,2))=($(vPreviousYear)>}EMPLID)

I have not checked anything else though.

bashar_f
Partner - Creator
Partner - Creator
Author

I must've missed it after trying to mix things up,


Count( {<(Left(Semester,2))=($(vPreviousYear)>}EMPLID)


Eventually, written like this, I get a red line just under the bracket in bold.

Not applicable

You can also keep your variables as you declared them initially and try the below:

count({<Semester={"=Left(Semester, 2) = $(vPreviousYear)"}>} EMPLID)

simondachstr
Specialist III
Specialist III

Learned something new

Not applicable

Martin,

Here's a link for another example of how to use this kind of search strings:

http://www.naturalsynergies.com/q-tip-5-show-top-performers-common-but-not-too-trivial/