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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Variable in a formula throws error

Hi all,

I have a Variable to get Jan of the selected Year. It works.

vTimeFloor=Date(makedate(Year,1),'MMM YY')

Then I have an expression to return Jan of the previous year. It works.

=date(addyears(Date(makedate(Year,1),'MMM YY'),-1),'MMM YY')

I put the Variable into the formula but it throws error that a ')' is expected

=date(addyears($(vTimeFloor),-1),'MMM YY')

error.PNG

Can anyone please help show me what formatting did I do wrong? This is very small issue but it costs me lots of time.

Many thanks.

3 Replies
tamilarasu
Champion
Champion

Hi Angie,

Try,

=date(addyears(vTimeFloor,-1),'MMM YY')

tresesco
MVP
MVP

When there is no selection in Year field or multiple years are in the scope, your expression might not work. Try re-defining your variable , like:

vTimeFloor=Date(makedate(Max(Year),1),'MMM YY')


And then, remove '$' sign when you are calling the function in the expression, like:


date(addyears(vTimeFloor,-1),'MMM YY'


Note:

'$' removal would not be required, if you remove the '=' sign from variable definition. I.e. either remove '=' from variable definition or '$' from variable calling in expression.

ChennaiahNallani
Creator III
Creator III

I have a Variable to get Jan of the selected Year. It works.

  1. vTimeFloor=Date(makedate(Year,1),'MMM YY'

try

  1. vTimeFloor=Date(makedate(max(Year,1)),'MMM YY')

Then I have an expression to return Jan of the previous year. It works.

  1. =date(addyears(Date(makedate(Year,1),'MMM YY'),-1),'MMM YY'

try

  1. =date(addyears(Date(makedate(max(Year,1)),'MMM YY'),-1),'MMM YY')

I put the Variable into the formula but it throws error that a ')' is expected

  1. =date(addyears($(vTimeFloor),-1),'MMM YY'

try

  1. =date(addyears($(vTimeFloor),-1),'MMM YY')