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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
dmohanty
Partner - Specialist
Partner - Specialist

Dynamically add the new columns in QVD?

Hi All,

I have a requirement like this below:

In a common folder, I have some new and old versions QVD, that are coming from SAME TABLE. The difference is that (for example), the OLD QVD has 2 fields: ID, Sales and the NEW QVD has ID, Name, Sales.

I have the Load script in Data Model as below:

Load

ID,

Name,

Sales

from .... *.QVD (qvd);

This script will fetch the data from all the NEW and OLD qvds from that folder.

My requirement:

Obviuosly the Load Script is failing where the script is fetching data from OLD qvd, as 'Name' is not available. So I want the functionaliy to be like this: It will search for all the fields in the QVD; IF AVAILABLE, then load the data into QV  and IF NOT AVAILABLE, the Dynamically create the Field and load the script. So that no error should come.

Hope I am clear. Could someone please help on this?

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

I think you will have to use a loop to load each qvd file and explicitly concatenate the loads. Something like this should do the trick:

Set vConcatenate = ;

sub ScanFolder(Root)

        for each FileExtension in 'qvd'

            for each FoundFile in filelist( Root & '\*.' & FileExtension)

                FileList:

                $(vConcatenate)

                LOAD *, '$(FoundFile)' as SourceFile

                FROM [$(FoundFile)] (qvd);

                Set vConcatenate = Concatenate;

            next FoundFile

         next FileExtension

         for each SubDirectory in dirlist( Root & '\*' )

             call ScanFolder(SubDirectory)

         next SubDirectory

end sub

Call ScanFolder('C:\QV_APP1\QVD_FILES') ;

The code above is adapted from an example Henric Cronström posted in this discussion: loop through to load all files from a folder and its subfolders?


talk is cheap, supply exceeds demand

View solution in original post

7 Replies
its_anandrjs
Champion III
Champion III

You can try with * key word and the fields that not required drop them like Drop Field FieldName;

Load


*


from .... *.QVD (qvd);

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

I think you will have to use a loop to load each qvd file and explicitly concatenate the loads. Something like this should do the trick:

Set vConcatenate = ;

sub ScanFolder(Root)

        for each FileExtension in 'qvd'

            for each FoundFile in filelist( Root & '\*.' & FileExtension)

                FileList:

                $(vConcatenate)

                LOAD *, '$(FoundFile)' as SourceFile

                FROM [$(FoundFile)] (qvd);

                Set vConcatenate = Concatenate;

            next FoundFile

         next FileExtension

         for each SubDirectory in dirlist( Root & '\*' )

             call ScanFolder(SubDirectory)

         next SubDirectory

end sub

Call ScanFolder('C:\QV_APP1\QVD_FILES') ;

The code above is adapted from an example Henric Cronström posted in this discussion: loop through to load all files from a folder and its subfolders?


talk is cheap, supply exceeds demand
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

First load the sources using LOAD * and collect into a single table. Then resuident load that table and fill in the null Names with the default value. Like this:

Data1:

Load *

from .... *.QVD (qvd);

Data2:

NoConcatenate

Load

     ID,

     If(IsNull(Name), 'Default Name', Name) As Name,

     Sales

Resident Data1;

Drop Table Data1;

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
dmohanty
Partner - Specialist
Partner - Specialist
Author


Hi Gysbert,

Thanks for this excellent solution. Learnt a new concept as well.

But I have a problem here as well. I can't use a '*' in Load Script as I am doing some field transformations. So, I have to list down all the fields in the Load Script.

Can this be tweaked some how?

dmohanty
Partner - Specialist
Partner - Specialist
Author

Thank you Jonathan for this kind help.

But when I am loading the all the data sources into a single table, actually in QV they are becoming 2 set of tables.

1st table (Table) has ID, Sales

2nd table (Table-1) has ID, Name, Sales.

So when I am  doing a resident from Table, 'Name' is not found.

Could you please help?

jonathandienst
Partner - Champion III
Partner - Champion III

Use Gysbert's script in place of the first load, then follow with the second part of my post.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
dmohanty
Partner - Specialist
Partner - Specialist
Author

Hi Gysbert and Jonathan,

Thank you for all these kind help. Really appreciate!