Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator II
Creator II

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
Highlighted
Creator II
Creator II

Re: how to declare a variable ?

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
Highlighted

Re: how to declare a variable ?

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

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Highlighted
Creator II
Creator II

Re: how to declare a variable ?

But how to use this in my script?

Highlighted

Re: how to declare a variable ?

Why not like below

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

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Highlighted
Creator II
Creator II

Re: how to declare a variable ?

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

Highlighted

Re: how to declare a variable ?

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..

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Highlighted
Creator II
Creator II

Re: how to declare a variable ?

This is not functioning

i have used 

Let Prev_Year = AddYears(Date,2);

Highlighted

Re: how to declare a variable ?

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

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Highlighted
Creator II
Creator II

Re: how to declare a variable ?

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

Highlighted

Re: how to declare a variable ?

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));

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)