Save Qlikview table as csv without header
Few months back I've needed a way to save Qlikivew table (during reload) to csv/txt file but without the field header (still cant remember the reason for this). But today I've saw that someone else is needing this so I've decided to solve this.
The issue
If we have the following script:
RawTable:
Load * Inline [
id, value
1 , 10
2 , 20
3 , 30
];
Store RawTable Into CSVOutput.csv (txt);
The output CSVOutput.csv file will look like this:
id,value
1,10
2,20
3,30
And what I want is the csv file to look like this:
1,10
2,20
3,30
The solution
There is no straighforward way to do this (or at least I don't know)
My idea is:
- to load only the first row from the required table
- "convert" all fields content into variables
- resident load all the rows (apart from the first row) and set column names as the variables content. For example:
RawData:
Load * Inline [
id,value
1,10
2,20
3,30
];
Get the first row:
id, value
1, 10
Loop through the values and create variable for each value. Using the data above will result in two variables: idColumn = 1 and valueColumn = 10.
Load the raw data excluding the first row:
TableToExport:
Load
id as ['$(idColumn)'],
value as ['$(valueColumn)']
Resident
RawData
Where
RecNo() > 1;
After executing the script below the result table will be
1,10 --> header
2,20 --> row
3,30 --> row
If you call Store on this table the resulted file will be a csv file without the original header.
The above script is simplified to demonstrate the the workflow. I've made a public Gist that can be used. The script will do all the work and there is only 2 variables that need to be supplied before call it:
- vNH_SourceTable - the name of the table that need to be exported
- vNH_OutputFile - the path of the exported file.
This way you can save the script to external file and just Include (or Must_Include) it.
Hope you like it!
Stefan