How to load QVDs dynamically based on Date and its availability

    In general , we will load the data in QVDs with daily basis or monthly basis with suffix.

    Sometimes we need to pick latest QVDs and load into the dashboard.

    I have QVDs like QVD_2017_01,QVD_2017_02,QVD_2017_03,QVD_2017_04,QVD_2017_04 and so on…

    I want to load latest QVDs like last 3 months if it exists.

    How to achieve this requirement?

    FOR i = 0 to vMaxMonthNumber 
     let Date_Suffix = date(floor(monthstart(today(), -vMaxMonthNumber+i)), 'YYYY_MM'); 
     LET vFileNotAvailable=isnull(QvdCreateTime('$(vQVDPath)\QVD Folder\Table1_$(Date_Suffix).qvd')); // if qvd exists then 0 else -1
     IF not $(vFileNotAvailable) then
     load *
     FROM $(vQVDPath)\QVD Folder\Table1_$(Date_Suffix).qvd (qvd);
     end if 
     LET vFileNotAvailable=isnull(QvdCreateTime('$(vQVDPath)\QVD Folder\Table2_$(Date_Suffix).qvd')); // if qvd exists then 0 else -1
     IF not $(vFileNotAvailable) then 
     load *
     FROM $(vQVDPath)\QVD Folder\Table2_$(Date_Suffix).qvd (qvd);
    end if;
    NEXT i;