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: 
Not applicable

To Display Current Year+2 and Current year -2

Hi All,

I have a field called "Production Year"

I need to display  " Current year + 2 and Current year -2 "

Eg: Current Year = 2014

I need a list box containing

2012, 2013, 2014(Current year), 2015 and 2016...

Can anyone pls help me with this..

Thanks,

praveen

1 Solution

Accepted Solutions
manideep78
Partner - Specialist
Partner - Specialist

Hi Praveen

Please try the below script:

LET vMin = Year(Today())-2;

LET vMax = Year(Today())+2;

YearTable:

LOAD

$(vMin)+ IterNo()-1 as ProductionYear

AutoGenerate 1 While $(vMin)+ IterNo()-1 <= $(vMax);

Hope this helps

Regards,

Manideep

View solution in original post

15 Replies
Not applicable
Author

I'd say try creating a master calendar in your load script, in this master calendar use variables for min date which would be your Production Year - 2 and then one for your max date which would be Production Year + 2.  This may be a useful post to check out.... Creating A Master Calendar

manideep78
Partner - Specialist
Partner - Specialist

Hi Praveen

Please try the below script:

LET vMin = Year(Today())-2;

LET vMax = Year(Today())+2;

YearTable:

LOAD

$(vMin)+ IterNo()-1 as ProductionYear

AutoGenerate 1 While $(vMin)+ IterNo()-1 <= $(vMax);

Hope this helps

Regards,

Manideep

john_duffy
Partner - Creator III
Partner - Creator III

Hi Praveen.

Do you want to show the string 2012,2013, etc. in the list box?

If so, you could create a field called ProdYears_Display:

(ProdYear - 2 ) & chr(44) & (ProdYear - 1) & chr(44) & (ProdYear) & chr(44) & (ProdYear + 1) & chr(44) & (ProdYear + 2) as ProdYears_Display

Not applicable
Author

Hi John Duffy,

Do you want me to write it in the load Script?

Not applicable
Author

Hi Manideep,

Thanks. I got it correct with your script.

I am a newbie. Can you please explain this script to me.?

Thanks,

Praveen

Not applicable
Author

Hi Manideep,

This is actually creating a temporary table. On selecting any date, it is not getting affected to the data. (If I select 2014 from it, it is not showing related data)

Not applicable
Author

Hi Praveen,

Add Date format function here , otherwise display the number,

YearTable:

LOAD
Date($(vMin)
+

IterNo()-1,'YYYY')

as

CurrentYear

AutoGenerate 1

While

$(vMin) +

IterNo()+1 <=

$(vMax);

manideep78
Partner - Specialist
Partner - Specialist

Hi Praveen

Yes, It will create a table with only one field called "ProductionYear". If there is already a field with the same name in any other tables, it will automatically link so that the data may get affected.

Let me know if your issue was resolved other wise send me the Sample app with some sample data so that we can see how we can generate the ProductionYear in the existing data model.

Regards

Manideep

Not applicable
Author

LOAD SHOW_ID AS PROJECT_ID,
SHOW_NAME,
REGION
LOCN
LIC_NBR,
TV_LEVEL_F,
TV_SEASON_F,
TV_SEASON_DESCR_F,
TV_SERIES_F,
TV_SERIES_DESCR_F,
WPR_GENRE_F,


PRDCTN_YR_F,-------->This is the column which has Production Year Data.         

PROD_TYPE_F


FROM
[\\ffeuscnm\Fins\VenSpre\SHOW.QVD]
(
qvd);

The above is the QVD which I have loaded. Now in editors MAIN Page, I have included the script which u have given me.


LET vMin = Year(Today())-2;
LET vMax = Year(Today())+2;
YearTable:
LOAD
$(vMin)+ IterNo()-1 as ProductionYear
AutoGenerate 1 While $(vMin)+ IterNo()-1 <= $(vMax);



I am getting the Table as how I need. but its not affecting the data. Can u help me with this ?