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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Consolidation of multiple columns in one

Hello all,

I implemented the following sample by for-loop how ever I did not get the proper result as desired:

data source:

 

CityJanuaryFebruaryMarch
New York100120130
LA200220230
Washington300320330
Seatthle400420430

My target is to reduce the number of columns to only three like

City     month     value

The first and easiest way is to concatenate columns as follows:

Target:

load

City,

'January' as month,

January as value

from xxx.csv;

concatenate (Target)

load

City,

'February' as month,

February as value

from xxx.csv;

concatenate (Target)

load

City,

'March' as month,

March as value

from xxx.csv;

but this is not the elegant way pf programing. So I tried to implement another way but without success:

tab1:

Load

null() as City,

null() as month,

null() as value

autogenerate 1;

for i =2 to NoOfFields(Target) step 1

let vFName = FieldName('$(i)','Target');

concatenate(tab1)

Load

City,

'['&'$(vFName)'&']' as month,

'$(vFName)' as value

Resident Target;

next

But something is wronge in this code and I do not know what exaclty? Any idea?

Thank you for help!

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

Guess what? QlikView has the prefect solution for you by providing the CrossTable prefix for the LOAD statement:

DATA:

CROSSTABLE(Month,Value)

LOAD * INLINE [

City,January,February,March

New York,100,120,130

LA,200,220,230

Washington,300,320,330

Seattle,400,420,430

];

2018-01-19 23_03_50-QlikView x64 - [C__Users_Petter_Downloads_# QC 2018-01-19 Expand rows.qvw_].png

View solution in original post

2 Replies
petter
Partner - Champion III
Partner - Champion III

Guess what? QlikView has the prefect solution for you by providing the CrossTable prefix for the LOAD statement:

DATA:

CROSSTABLE(Month,Value)

LOAD * INLINE [

City,January,February,March

New York,100,120,130

LA,200,220,230

Washington,300,320,330

Seattle,400,420,430

];

2018-01-19 23_03_50-QlikView x64 - [C__Users_Petter_Downloads_# QC 2018-01-19 Expand rows.qvw_].png

Anonymous
Not applicable
Author

Thank you very much Petter.