Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
RAJ6
Contributor III
Contributor III

Transpose Columns to Rows

Hi Talend Folks,

 

  • In my excel have 400 rows and 500 columns are there. 
  • I have a input excel source like below screenshot format

0683p000009LrIT.png

  • I need to convert data like below screenshot format using talend tool.
  • Expected Output.

0683p000009LrSI.png

  • Please tell me how to Transpose Columns to Rows data above screenshots.
Labels (2)
5 Replies
Anonymous
Not applicable

Hi there,

 

Talend and similar ETL tools are very much about dealing with fixed, structured data, and the standard components are geared up for this.

 

In this case, there are presumably a dynamic number of columns, and the column headings are going to change, which means these standard components and standard approaches aren't suitable.

 

As I've explained in your other thread regarding the column names in Talend, you also won't be able to use the dates in your spreadsheet as columns within your job.

 

Assuming you can't just pivot this in Excel itself, which is very quick and easy to do, then you will either require custom code in a tJavaFlex component, or maybe a custom component.

 

Take a look on Talend Exchange (https://exchange.talend.com/) and see if there's something suitable.

 

Regards,

 

 

Chris

Anonymous
Not applicable

Hi , 

I had a similar scenario where i want to transpose some columns to rows ,where i used tjavaflex to achieve .

 

Tjavaflex Details :

Start code - Here get the column names which we need to populate in rows and make a for loop with that number, In my case i have 5 columns and i want to transpose last 3 columns ,

 

String splitString = row7.toString().substring(row7.toString().indexOf("[")+1,row7.toString().length()-1);

String[] arr1;
arr1 = splitString.split(",");
String[] arr2;
int[] numArr = {2,3,4}; // put the position number (counting from 0) of the columns you want to transpose - for me last 3 cols
String temp = "";
for(int j = 0;j<numArr.length;j++)
{
if(j!=numArr.length-1)
temp+=arr1[numArr[j]]+",";
else
temp+=arr1[numArr[j]];
}

arr2 = temp.replaceAll("=null","").split(",");

for(int i =0 ;i<arr2.length;i++)
{

Main CodeHere Populate the two new columns , 

row8.col_name = arr2[i];
String temp2 = row7.toString().substring(row7.toString().indexOf(arr2[i]+"="),row7.toString().length()-1)+",";
row8.col_value = temp2.substring(temp2.indexOf("=")+1,temp2.indexOf(","));

End CodeClose the forloop as ' } ' .

}0683p000009LrvB.pngTest Job0683p000009Lrv7.pngSchema - fixedFlowInp & tjavaflex0683p000009Ls5L.pngSample Input0683p000009Ls5o.pngAchieved Output (Transposed one)

Anonymous
Not applicable

The simple solution for this is use tUnpivotRow(from talend exchage)

follow the link for its explanation

https://www.datalytyx.com/how-to-denormalise-a-dataset-using-talends-tunpivotrow/

fjblau
Contributor
Contributor

tUnPivotRow is NOT compatible with Talend Studio 8

 

jlolling
Creator III
Creator III

You can use the component tFileExcelSheetInput together with tFileExcelSheetInputUnpivot.

https://github.com/jlolling/talendcomp_tFileExcel/blob/master/doc/tFileExcelSheetInput.pdf

These components are part of the well known excel components tFileExcel* component suite.

It allows also to have a variable number of columns and you do not have to deal with the massive amount of columns at all. Everything is done automatically.