Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

jtay
New Contributor III

create date range variable for rolling 13 months

I am working on a chart that needs to show a default view of the last 13 months.

I want to reuse the same 13 month range for other visualizations so I’ll use a variable.

I think my set analysis should look like this:

Count({<$(vAriable)>}Distinct Field1)

 

I have the begin and end dates calculating correctly – when viewed through a KPI. 

date(MonthName(addmonths(vToday),-13)) gives me April 1, 2016 (which is correct)

date(MonthEnd(vToday))    gives me May 31, 2017 (which is correct)

vToday = Today()

   

I now need to put the range together in a format that will work in the variable – but I need some help please.  thanks

This is where I am now…

 

{">$(=date(MonthName(addmonths(vToday),-13))) <=$(=date(MonthEnd(vToday)))"}

 

1 Solution

Accepted Solutions
jtay
New Contributor III

Re: create date range variable for rolling 13 months

Thanks Chris - your last sentence gets to the root of the problem.  We need to be able to select dates within and also outside that 13 month range and have the graph update.  This is what I ended up putting together:

My variable $(vRolling13) = MonthSequence = {">$(=max(MonthSequence)-14)<=$(=max(MonthSequence))"}

Monthsequence is just a number count assigned to each month in the master calendar. 

 

Count({<$(vRolling13) >} Distinct Value1)

thanks!

3 Replies
aarkay29
Valued Contributor

Re: create date range variable for rolling 13 months

May be this as variable

vTest='>'& (date(MonthStart(addmonths(Today(),-13)))) &'<='&(date(MonthEnd(Today())))

sum({<[Order Date]={"$(=$(vTest))"}>}Sales)

chriscammers
Contributor III

Re: create date range variable for rolling 13 months

What you have there is a little bit of tricky syntax. I have found that you have to calculate the entire string, you cannot just rely on the dollar sign expansion to concatenate the string together ">$()<=$()" syntax does not work. so something like this should do the trick... $(='>' & date(MonthName(addmonths(vToday),-13)) & '<=' & date(MonthEnd(vToday)))

I find that with this kind of expression you also need to make sure other calendar selections are not conflicting with the 13 month set analysis.

jtay
New Contributor III

Re: create date range variable for rolling 13 months

Thanks Chris - your last sentence gets to the root of the problem.  We need to be able to select dates within and also outside that 13 month range and have the graph update.  This is what I ended up putting together:

My variable $(vRolling13) = MonthSequence = {">$(=max(MonthSequence)-14)<=$(=max(MonthSequence))"}

Monthsequence is just a number count assigned to each month in the master calendar. 

 

Count({<$(vRolling13) >} Distinct Value1)

thanks!