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: 
Meg00
Contributor III
Contributor III

if statement, greater than and less than MAX

Hi everyone! 
I am trying to create a variable. The result I'm trying to achieve is depending on selected period (YYYYMM) I want the variable to always show selected period-1 to selected period +11 (rolling 12 if you want).

I've created a PeriodCounter that looks correct:

PeriodPeriodCounter
2021011
2021022
2021033
2021044

etc.

And then trying this syntax:

vPeriods=

if(PeriodCounter >= '$(=Max(PeriodCounter)-1)' or PeriodCounter < '$(=Max(PeriodCounter)+11)', Period)

and it looks correct: 

Meg00_0-1617801129194.png

so in this case 202104 is selected, I use the vPeriods as dimension in table, but it only shows 202104.

 

I have a feeling I've messed up the syntax somewhere.

Does anyone have a better option or know where I've done something wrong?

 

 

Labels (5)
2 Solutions

Accepted Solutions
Gysbert_Wassenaar

I'd suggest you solve this problem in the load script by creating an AsOf table.

See this article for example: https://community.qlik.com/t5/QlikView-Documents/Calculating-rolling-n-period-totals-averages-or-oth...


talk is cheap, supply exceeds demand

View solution in original post

Dalton_Ruer
Support
Support

When you say that 202104 is SELECTED I take that to mean that you have physically selected it in a filter. In which case I would fully expect that it is the only that shows. 

I think what you likely need is a DATE ISLAND so that you can select it from the island table which isn't associated to your other data. Then you should be able to accomplish what you are looking to do. Or you can utilize SET ANALYSIS to override the period selection. Not sure of your data model and use case. 

Here is 1 example of a Master Calendar as a Data Island https://optimalbi.com/crafting-qlik-sense-calendars-part-3-of-4-date-islands/

 

View solution in original post

3 Replies
Gysbert_Wassenaar

I'd suggest you solve this problem in the load script by creating an AsOf table.

See this article for example: https://community.qlik.com/t5/QlikView-Documents/Calculating-rolling-n-period-totals-averages-or-oth...


talk is cheap, supply exceeds demand
Dalton_Ruer
Support
Support

When you say that 202104 is SELECTED I take that to mean that you have physically selected it in a filter. In which case I would fully expect that it is the only that shows. 

I think what you likely need is a DATE ISLAND so that you can select it from the island table which isn't associated to your other data. Then you should be able to accomplish what you are looking to do. Or you can utilize SET ANALYSIS to override the period selection. Not sure of your data model and use case. 

Here is 1 example of a Master Calendar as a Data Island https://optimalbi.com/crafting-qlik-sense-calendars-part-3-of-4-date-islands/

 

Meg00
Contributor III
Contributor III
Author

you're absolutely right, I still had the expression I made for current period in mind and thought I could work from that.
If( Date#(Period&'01', 'YYYYMMDD') >= MonthStart(AddMonths($(CurrentDate), - 1)) and Date#(Period&'01', 'YYYYMMDD') < MonthStart(AddMonths($(CurrentDate), 11)), Period)