Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
onkar1988
Contributor III
Contributor III

Need to load data only for max(year) in QlikSense load script

Hi All,

I have data for multiple Reporting years in my oracle table year_sales, I need to load data for only latest year. I am trying below script, however, not sure data is not getting loaded in Final table. Please guide me, I am not able to identify if I have made any silly mistake.

 

File_status:
LOAD
RPT_YEAR,
SELECT
RPT_YEAR,
FROM "Year_sales" ;


TEMP:
LOAD
Max(RPT_YEAR) as Current_Year
Resident File_status;

LET v_max_year = floor(peek('Current_Year'));

Final:
Load *
Resident File_status
where RPT_YEAR = $(v_max_year);

Drop Table TEMP;

Drop Table File_status;

 

Thanks in advance.

 

Regards,

Onkar Kulkarni

Labels (2)
1 Solution

Accepted Solutions
sumanta1234
Partner - Creator
Partner - Creator

Hi

Use the below code:

File_status:
LOAD
RPT_YEAR,
SELECT
RPT_YEAR,
FROM "Year_sales" ;


TEMP:
LOAD
Max(RPT_YEAR) as Current_Year
Resident File_status;

LET v_max_year = floor(peek('Current_Year'));

NOCONCATENATE
Final:
Load *
Resident File_status
where RPT_YEAR = $(v_max_year);

Drop Table TEMP;

Drop Table File_status;

View solution in original post

4 Replies
sumanta1234
Partner - Creator
Partner - Creator

Hi

Use the below code:

File_status:
LOAD
RPT_YEAR,
SELECT
RPT_YEAR,
FROM "Year_sales" ;


TEMP:
LOAD
Max(RPT_YEAR) as Current_Year
Resident File_status;

LET v_max_year = floor(peek('Current_Year'));

NOCONCATENATE
Final:
Load *
Resident File_status
where RPT_YEAR = $(v_max_year);

Drop Table TEMP;

Drop Table File_status;

naumanshah
Contributor III
Contributor III

You may simply restrict the year while fetching from Oracle, e.g.

...

SELECT
   RPT_YEAR
FROM "Year_sales"
WHERE RPT_YEAR = EXTRACT(YEAR FROM SYSDATE)

narband2778
Creator II
Creator II

Hi,

 

Try This

 

File_status:
LOAD
RPT_YEAR,
SELECT
RPT_YEAR,
FROM "Year_sales" ;


TEMP:
LOAD
Max(Floor(RPT_YEAR)) as Current_Year
Resident File_status;

LET v_max_year = peek('Current_Year');

Drop Table TEMP;

Drop Table File_status;

Final:
Load *
FROM "Year_sales"
where RPT_YEAR = $(v_max_year);

 

Thanks,
Naresh

 

onkar1988
Contributor III
Contributor III
Author

Thanks for the quick reply. I cannot use sysdate as not necessary the max (year) will be sysdate year.  sometimes latest year could be 2015 in data.