Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Every month I create a qvd file but in the end I want all my qvd-files to end up in a grand total.
I have succeeded to create the monthly qvd-file and then save it as a total file (code below). These two files are now identical. So the next month I first want to save my new monthly file and then I want to add it to the total file and thereafter save the total file. How do I do this? This is my code so far.
// Get data;
AT_$(vMonth):
LOAD *
FROM
$(vRawFolder)\AT_$(vMonth).dat
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);
// Save the monthly qvd-file
STORE AT_$(vMonth) into $(vQvdFolder)\AT_$(vMonth).qvd(qvd);
// Save my first month as the total
GrandTotal:
LOAD * FROM $(vQvdFolder)\AT_$(vMonth).qvd(qvd);
// Store my total file
STORE GrandTotal into $(vQvdFolder)\UC.qvd(qvd);
Use a pattern like this:
// Get data for current month
AT_$(vMonth):
LOAD *
FROM $(vRawFolder)\AT_$(vMonth).dat
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);
// Save the monthly qvd-file
STORE AT_$(vMonth) into $(vQvdFolder)\AT_$(vMonth).qvd(qvd);
If Alt(QvdNoOfRows('$(vQvdFolder)\UC.qvd'), 0) > 0 Then
// Load prior months from total file
GrandTotal:
LOAD * FROM $(vQvdFolder)\UC.qvd(qvd);
// Add to grand total
Concatenate(GrandTotal)
LOAD * FROM $(vQvdFolder)\AT_$(vMonth).qvd(qvd);
Else
// Save my first month as the total
GrandTotal:
LOAD * FROM $(vQvdFolder)\AT_$(vMonth).qvd(qvd);
End If
// Store my total file
STORE GrandTotal into $(vQvdFolder)\UC.qvd(qvd);
If this script is run twice, then the current month will be duplicated, so you might prefer to add a conditional to the preload in the if block:
// Load prior months from total file
GrandTotal:
LOAD * FROM $(vQvdFolder)\UC.qvd(qvd)
Where Month <> $(vMonth); // assumes a numerical month
Adjust the logic of the Where to match your model.
I see your point and I also see that in my code I forgot to replace UC with grandtotal in some places.
But, the autocorrect in the script doesn't like this line, can you see what is wrong with it?
If Alt(QvdNoOfRows('$(vQvdFolder)\UC.qvd'), 0) > 0 Then
Or is there a FileExist-function that I can use?