Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to declare a variable ?

Hi

I want to compare two years sale ie the current year should be the 2017 and prev year should be either 2016,2015 or any other year less that 2017

so in my script i have declared my variable as :-

Let currentdate =DATE(Today(1)-1,'YYYYMMDD');

Let Curr_Year = Year(Today());

let prev_year=..............

createdate is a column in database

Date#(CreateDate, 'YYYYMMDD') as Sold_Date,
month(Date#(CreateDate, 'YYYYMMDD')) as Sold_Month,
year(Date#(CreateDate, 'YYYYMMDD')) as Sold_Year,


in my expression i have expression for prev_year and curr_year

curr_year expression:-


=num(
sum(if(Sold_Date <= MakeDate(Curr_Year,month(To),day(To)) and Sold_Date >= MakeDate(Curr_Year,month(From),day(From)),  [inv value]))/Sales_INR_Unit,
'#,##0.0')

for prev_year

=num(
sum(if(Sold_Date <= MakeDate(Prev_Year,month(To),day(To)) and Sold_Date >= MakeDate(Prev_Year,month(From),day(From)),  [inv value]))/Sales_INR_Unit,
'#,##0.0')

Now what all changes are required for prev_year expressions? and for prev_year variable declration????????

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

variable used in text box is working but charts are not showing results, it can be seen in image

View solution in original post

27 Replies
Anil_Babu_Samineni

Please have a look addyears - script and chart function ‒ Qlik Sense

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

But how to use this in my script?

Anil_Babu_Samineni

Why not like below

LET prev_year= AddYears(Your Intend, -1);

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

but i think it will give me result as 2016

but i want on input of  a year  in input box, the chart should start showing the appropriate result

for eg if i input 2015 in input box  the results should be shown on chart

Anil_Babu_Samineni

True, You can simply the expression like Variable as Input box and call that variable in Front End of each Report until unless it won't. That means little in detail

LET Var = Max(Year);

So, In your list box it has Var as "Used Variables"

And then, the analysis need to be changes as per input from customer. So you have to enable like

Sum({<Year = {$(=Var)}>} Sales) // this deserve, If we add manually input from input box..

Does it make sense..

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

This is not functioning

i have used 

Let Prev_Year = AddYears(Date,2);

Anil_Babu_Samineni

Let's consider Date has 12/12/2017, 11/12/2017..

How and Which Date field picks to go backward.. That means, you have to use Max() and Min() to get into work..

Note - If none of them make sense for you i would suggest please come up with example and explain same as needed

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

now how to use max iand min in sa,me above varialable declaration?

Anil_Babu_Samineni

Not sure, Your thread is different and your conclusion is different. May be this?

Let Prev_Max_Year = Date(AddYears(Max(Date),2));

Let Prev_Min_Year = Date(AddYears(Min(Date),2));

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful