Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Transforming the table

Hi

I have file with  5 column.

example:

YearCityTypeSalesQuantity
2017LondonA112
2017LondonB123
2018LiverpoolA134
2018LiverpoolB155

and i need this tabel

YearCitySales_ASales_BQuantity_AQuantity_B
2017London111223
2018Liverpool131545

Please help

1 Solution

Accepted Solutions
sunny_talwar

Try this

Table:

LOAD * INLINE [

    Year, City, Type, Sales, Quantity

    2017, London, A, 11, 2

    2017, London, B, 12, 3

    2018, Liverpool, A, 13, 4

    2018, Liverpool, B, 15, 5

];


FinalTable:

LOAD Distinct Year,

City

Resident Table;


FOR i = 1 to FieldValueCount('Type')


LET vType = FieldValue('Type', $(i));

Left Join (FinalTable)

LOAD Distinct Year,

City,

Sales as [Sales_$(vType)],

Quantity as [Quantity_$(vType)]

Resident Table

Where Type = '$(vType)';


NEXT


DROP Table Table;

View solution in original post

3 Replies
sunny_talwar

Try this

Table:

LOAD * INLINE [

    Year, City, Type, Sales, Quantity

    2017, London, A, 11, 2

    2017, London, B, 12, 3

    2018, Liverpool, A, 13, 4

    2018, Liverpool, B, 15, 5

];


FinalTable:

LOAD Distinct Year,

City

Resident Table;


FOR i = 1 to FieldValueCount('Type')


LET vType = FieldValue('Type', $(i));

Left Join (FinalTable)

LOAD Distinct Year,

City,

Sales as [Sales_$(vType)],

Quantity as [Quantity_$(vType)]

Resident Table

Where Type = '$(vType)';


NEXT


DROP Table Table;

Anonymous
Not applicable
Author

Anonymous
Not applicable
Author

It works

thank you for the fast reponse