Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

cancel
Showing results for 
Search instead for 
Did you mean: 
lawrance
Creator II
Creator II

How to get last two years record from qvd?

Hi,

I want to get last two years record from qvd ans store it in another qvd.

Thanks,

Lawrance

1 Solution

Accepted Solutions
rulohx87
Contributor III
Contributor III

May be like this

LOAD * FROM ARCHIVO.QVD (QVD)

WHERE Year(DateField) >= Year(Today()) - 2;

Regards

View solution in original post

4 Replies
vishsaggi
Champion III
Champion III

(Do you have a datefield or year field in your old qvd just use it and try like below?)

TWOYEAR:

LOAD *

FROM yourpath\yourqvdname.qvd(qvd)

WHERE Year >=2015;

STORE TWOYEAR INTO yourqvdpath\yournewqvdname.qvd(qvd);

rulohx87
Contributor III
Contributor III

May be like this

LOAD * FROM ARCHIVO.QVD (QVD)

WHERE Year(DateField) >= Year(Today()) - 2;

Regards

View solution in original post

atkinsow
Specialist II
Specialist II

To keep the qvd load optimized you can also do something like this:

//Assign variables for start date and end date.

let vEndDate=num(today());

let vStartDate=num(yearstart(today(),-2));

//Assign variable for number of days between start and end dates.

Let DayCount =$(vEndDate)+1-$(vStartDate);

DateFilters:

LOAD

date($(vEndDate)+1-recno(),'MM/DD/YYYY') AS NameOfYourDateField

AUTOGENERATE $(DayCount);

Data:

Load *

from yourpath\yourqvd.qvd (qvd)

where exists(NameOfYourDateField);

STORE Data INTO yourpath\yournewqvd.qvd(qvd);

Drop table DateFilters;

rulohx87
Contributor III
Contributor III

Use the follow function:

AddYears(startdate, n)


addyears ('2009-01-29',3) = '2012-01-29'

addyears ('2009-01-29',-1) = '2008-01-29'