Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
AlexWest
Creator
Creator

Load exact patitioned QVD-file in ODAG

Hi, everyone!
My last question was about making partitions from one QVD to several smaller.
And kind user Brunobertels sent me a link to a post, how to do automatic partitions.

And now, I have many pratitioned QVD-files and task:
I have to load those QVD-files which have only data by asked dates in ODAG request.

I just made a next script:

//first check if it's not an ODAG request, but a common load from current window
if '$(odagActive)' = '' then
   set 'odag_Date' = '''01.07.2019''';
end if;

[Tasks]:

LOAD
   TaskID,
   ContactID,
   CompanyID,
   CreationDate,
   TaskExpDate,
   EditDate,
   TaskStatus,
   CreatedUserID,
   ResponsibleUserID,
   TaskName
FROM[lib://DataFiles/CRM_Tasks_*.qvd](qvd)
where Match(CreationDate,$(odag_Date));

But as you can see, it's a bad script, coz it loads all the files(((
Please help me to load exact files with dates which was requested.

Here's my QVDs:

lib://DataFiles/CRM_Tasks_m01_y2019.qvd
lib://DataFiles/CRM_Tasks_m02_y2019.qvd
lib://DataFiles/CRM_Tasks_m03_y2019.qvd
lib://DataFiles/CRM_Tasks_m04_y2019.qvd
lib://DataFiles/CRM_Tasks_m05_y2019.qvd
etc till the end of 2020.

Labels (2)
11 Replies
steeefan
Luminary
Luminary

Let's assume your date selection string is formatted as this when selecting more than one date: '01.08.2019','01.09.2019','01.10.2019'. This code would then go over every date and fetch the relevant data:

// Initialize results table
Tasks:
NOCONCATENATE LOAD * INLINE [
  TaskID
];

// Testing only
SET odag_Date = '''01.08.2019'',''01.09.2019'',''01.10.2019''';

// Iterate over each date
FOR EACH vDate IN $(odag_Date)

  TRACE Working on ODAG date $(vDate);

  // Create values to select relevant QVD file
  LET vODAGDate = Num(Date(Date#('$(vDate)', 'DD.MM.YYYY')));
  LET vQVDMonth = Num(Month('$(vODAGDate)'));
  LET vQVDMonth = If($(vQVDMonth) < 10, '0', '') & $(vQVDMonth);
  LET vQVDYear = Year($(vODAGDate));

  LET vQVDFile = 'CRM_Tasks_m$(vQVDMonth)_y$(vQVDYear).qvd';
  TRACE $(vQVDFile);

  // Optimized load w/o filtering from relevant QVD file
  Tasks_stg1:
  LOAD
    //..
  FROM
    [lib://DataFiles/$(vQVDFile)]
    (qvd);

  // Filtered load on data just loaded
  // Add to results table
  CONCATENATE (Tasks) LOAD
    //..
  RESIDENT
      Tasks_stg1
  WHERE
      Match(CreationDate, $(odag_Date));
  
  DROP TABLE Tasks_stg1;

NEXT vDate;
AlexWest
Creator
Creator
Author

Yes, sir!
Thank you so much!
This script is working exactly as needed!
Now I'm going to learn your script and understand how it works XD

Again... Thank you so much!