Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
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????????

27 Replies
Anonymous
Not applicable
Author

i have already mentioned above

for 2016

=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')

Prev_Year

Let Prev_Year = AddYears(10/12/2017,-2); so its giving result as 10/12/10 but i want to show only 2015 in text box

and chart should also show appropriate results

Anil_Babu_Samineni

I even stated same with first reply. Try a shot

Let Prev_Year = Year(Today())-2; // this will return 2015

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 i was doing but now i want that when i will select date in calender as 20/12/2016 , the text box should show year as 2016 and the corresponding sales in chart

how to declare variable in such case?

Anil_Babu_Samineni

I already suggest the link which CookBook. From there you will get everything. Anyway

First try plane instead of Variable for now

You have calendar that means field name or Calendar object.

Calendar object - Means you have done using Variable/ Simple Field

And finally, Try AddYears(Year(Max(FieldName)), -2) OR Year(Max(FieldName))-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
Anonymous
Not applicable
Author

i have used variable

min(sold_date)ttt.pngsecondly if i have to use it plain not as variable then how to use?

i mean simply ishould write in script or expression instead of prev_year variable?

Anil_Babu_Samineni

When i say Plane - It should be Text object

So, To demonstrate your issue you could use From Variable instead of using FieldName.

If none of them not working. Please share some Mock up test (I apologies) for asking...

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
Anil_Babu_Samineni

Not sure, Issue got resolved? If so, I would recommend you to do your Job (Please close this thread)

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
Anil_Babu_Samineni

When i say, Close this thread means, You have to mark proper answer as "Correct Answer" using Flag..

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