Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
curiousfellow
Specialist
Specialist

strange results when calculating variable from varaible filled with calendar /slider value

I have a simple date slider with min and max value and set the format to d-m-y

The value is stored in a variable called v_today

I thought i could calculate other variables based on the stored value

I tried a lot different expressions and formats but I get strange results.

When I add a variable with expression =addyears($(v_today),1) I get strange results.

 

Please have a look at enclosed qvw and tell me what i am doing wrong

 

 

 

 

 

Labels (3)
1 Solution

Accepted Solutions
Gysbert_Wassenaar

The AddYears function returns a date. Your variable gets the value of that date, but not the numeric value of that date, but its text representation: 23-10-2018. When you evalutate that value with dollar expansion you get $(23-10-2018) which gives the result of 23 minus 10 minus 2018. That's -2005. If you don't dollar expand it but use it in the Date function you get Date(23-10-2018) which is Date(-2005) which gives the resulting date 4-7-1894. 

So how do you fix that? One way is to create your variable as =num(addyears(v_today, -1)) so that it always gets a numeric value which can be evaluated correctly in a dollar expansion and also works correctly as input for the Date function.


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

The AddYears function returns a date. Your variable gets the value of that date, but not the numeric value of that date, but its text representation: 23-10-2018. When you evalutate that value with dollar expansion you get $(23-10-2018) which gives the result of 23 minus 10 minus 2018. That's -2005. If you don't dollar expand it but use it in the Date function you get Date(23-10-2018) which is Date(-2005) which gives the resulting date 4-7-1894. 

So how do you fix that? One way is to create your variable as =num(addyears(v_today, -1)) so that it always gets a numeric value which can be evaluated correctly in a dollar expansion and also works correctly as input for the Date function.


talk is cheap, supply exceeds demand
curiousfellow
Specialist
Specialist
Author

Thank you for your quick answer