Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Darumaka
Contributor
Contributor

Add monthly qvd-file to total qvd-file

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);

 

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

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.

 

 

 

 

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Darumaka
Contributor
Contributor
Author

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

Darumaka
Contributor
Contributor
Author

Or is there a FileExist-function that I can use?