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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
annabergendal
Partner - Creator
Partner - Creator

Merge two string variables into one

I want to create a variable with two other variables, year and previous week.

=$(vYear) &' - '& $(vPreviousWeek)

It doesn't work though, what is the syntax? I want it to be for example "2014-39"

Thanks

1 Solution

Accepted Solutions
maxgro
MVP
MVP

it depends on how you define vYear and vPreviousWeek

example, with this in an input box

vYear                   =max(Year)               // field Year

vPreviousWeek     =max(Week)             // field Week

v                         =$(vYear) & '-' & $(vPreviousWeek)

you get

1.png

View solution in original post

8 Replies
maxgro
MVP
MVP

it depends on how you define vYear and vPreviousWeek

example, with this in an input box

vYear                   =max(Year)               // field Year

vPreviousWeek     =max(Week)             // field Week

v                         =$(vYear) & '-' & $(vPreviousWeek)

you get

1.png

danieloberbilli
Specialist II
Specialist II

And you have to do it in the variable-window of the frontend - not in the script as you have to replace the $-signs to avoid QV in executing them unintentional

annabergendal
Partner - Creator
Partner - Creator
Author

vYear = Year($(vToday)) and same for vWeek.

Should I define withuot '$' ? But it doesn't work without...

With the syntax =$(vYear) & '-' & $(vPreviousWeek) I get 1976 when vYear is 2014 and vWeek is 39.

vardhancse
Specialist III
Specialist III

=$(vYear) & ' - ' & $(vPreviousWeek)

danieloberbilli
Specialist II
Specialist II

seems that vPreviousWeek is also defined as year - thats why it substracts 39 years. Try Week() instead of Year

Not applicable

Anna,

Pls share your complete variable logic & it depend on the logic being user there.normally if you variable having year

To use that varable, following is the syntax

$(variablename) or $(=variablename)

yoy can use eaither of those two.

annabergendal
Partner - Creator
Partner - Creator
Author

Thanks, I think this was actually my problem, when using the created variable in a script I used $, when I take that away it works

Not applicable

I look at your statement: vYear = Year($(vToday)) and same for vWeek


If you store "Today" date in a variable and then put it, as a date field, in other date function (Year($(Today)) in your case) that function may have a problem to convert your $(Today) variable.


To solve this you can replace

Year ($ (vToday))

with the syntax:

Year (Today ()).

Today() function will be converted correctly by Year() function.

The same for the week function.