Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
tinkerz1
Creator II
Creator II

Variable to set lookback period on charts

Hi,

Is there any way to use a variable to set the number of data items to load, working back from the latest date.

For instance, if there are 12 dates on the x axis and I want the last 6 only how would I do it.

x - axis

1/06  1/07  1/08  1/09  1/10  1/11 1/12

Then use the same approach but use a variable to set 9 months?

1/12/2010

1/11/2010

1/10/2010

1/09/2010

1/08/2010

1/07/2010

1/06/2010

1/05/2010

1/04/2010

1/03/2010

1/02/2010

1/01/2010

6 Replies
Anonymous
Not applicable

you can either do it in Dimension or in Expression (then you Need to do it for all expressions!)

Dimension:

if (yourdatefield>=mindate and yourdatefield<=maxdate, yourdatefield)

mindate could be addmonths(max(yourdatefield),-6) and maxdate could be max(yourdatefield)

i would use variables to hold the Dates

expression

sum({<yourdatefield={'>=$(=mindate)<=$(=maxdate)'}>}Amount)

tinkerz1
Creator II
Creator II
Author

I have written this in my dimension

 

=Date(if(Num#(Dates)>=Min_Date and Num#(Dates)<=Max_Date,Num#(Dates)),'DD/MM/YY')

And my variables are

Min_Date

addmonths(max(num#(Dates)),-6)

Max_Date

max(num#(Dates))

The dates across the bottom are correct, but I get an extra column showing the total.

It must be adding all the cells up that are inside the range, how do i get around this?

tinkerz1
Creator II
Creator II
Author

Also I can't change the variable expression Min_date

 

=addmonths(max(num#(Dates)),-6)

Every time I try and change the 6 to a 3, I press OK but the 6 wont change

Any Ideas?


tinkerz1
Creator II
Creator II
Author

  This now works for the window, if I change [Lookback period for dates], the window changes.

But I still get the total column on the end.

=addmonths(max(num#(Dates)),-([Lookback period for dates]))

 

=date(max(num#(Dates)))

tinkerz1
Creator II
Creator II
Author

The total at the end is the total of all date outside the date range.

How is this working to create this?

tinkerz1
Creator II
Creator II
Author

In Dimensions 'surpress when value is null'

It looks like that total data was the 'FALSE' side of the equation that was plotting.