Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi scripting experts, I have below the table, need to export to csv/txt with a specific header. Any thoughts?
Input:
Customer, Sales
A,100
B,200
C,300
D,400
E,500
Required output in txt/csv:
Total rows: 5 A,100 B,200 C,300 D,400 E,500
Not able to upload a qvf, so I attached the codes:
Table1: LOAD * INLINE [ Customer, Sales A,100 B,200 C,300 D,400 E,500 ]; Store Table1 into [lib://Data/Table1.txt](txt, delimiter is '|');
If you just use a little number of columns this would be a perfect solution:
Table1: LOAD Customer & '|' & Sales as Reg INLINE [Customer, Sales A,100 B,200 C,300 D,400 E,500 ]; Header: Load 'Total rows: ' & Count(Reg) as numReg Resident Table1; LET vLabelColumn1 = peek('numReg',0,'Header'); TableToExport: LOAD PurgeChar(Reg,'"') as '$(vLabelColumn1)' RESIDENT Table1; DROP TABLE Table1, Header; Store TableToExport into [Table1.txt](txt);
The result will be:
Total rows: 5 A|100 B|200 C|300 D|400 E|500
Hi,
You can try with this code:
Table1: LOAD * INLINE [Customer, Sales A,100 B,200 C,300 D,400 E,500 ]; Header: Load 'Total rows: ' & Count(Customer) as numReg Resident Table1; let vLabelColumn1 = peek('numReg',0,'Header'); let vLabelColumn2 = ' '; TableToExport: LOAD Customer as '$(vLabelColumn1)', Sales as '$(vLabelColumn2)' RESIDENT Table1; DROP TABLE Table1, Header; Store TableToExport into [Table1.txt](txt, delimiter is '|');
But the solution isn't perfect because it includes the delimiter in the header 😞
Total rows: 5| A|100 B|200 C|300 D|400 E|500
If you just use a little number of columns this would be a perfect solution:
Table1: LOAD Customer & '|' & Sales as Reg INLINE [Customer, Sales A,100 B,200 C,300 D,400 E,500 ]; Header: Load 'Total rows: ' & Count(Reg) as numReg Resident Table1; LET vLabelColumn1 = peek('numReg',0,'Header'); TableToExport: LOAD PurgeChar(Reg,'"') as '$(vLabelColumn1)' RESIDENT Table1; DROP TABLE Table1, Header; Store TableToExport into [Table1.txt](txt);
The result will be:
Total rows: 5 A|100 B|200 C|300 D|400 E|500
Thanks, Albert! excellent solution!