<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic [resolved] Transposing input file with dynamic number of columns in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312533#M83477</link>
    <description>I have a very tricky situation and have yet to come up with my own solution. I have an input csv file that has a dynamic number of columns and need to transpose this file to create a desired output file. The input file looks like this:
&lt;BR /&gt;
&lt;BR /&gt;ID1 | Units1 | Count | Val1a | Val2a | Val3a | Val1b | Val2b | Val3b | Val1c | Val2c | Val3c
&lt;BR /&gt;ID2 | Units2 | Count | Val1d | Val2d | Val3d | Val1e | Val2e | Val3e
&lt;BR /&gt;
&lt;BR /&gt;As you can see, the Val's are in triplets on each row and I need the triplets to stay together. The Count column holds a number of how many triplets are found on that row as each row is dynamic. The final output I need is:
&lt;BR /&gt;
&lt;BR /&gt;ID1 | Units1 | Val1a | Val2a | Val3a
&lt;BR /&gt;ID1 | Units1 | Val1b | Val2b | Val3b
&lt;BR /&gt;ID1 | Units1 | Val1c | Val2c | Val3c
&lt;BR /&gt;ID2 | Units2 | Val1d | Val2d | Val3d&amp;nbsp;
&lt;BR /&gt;ID2 | Units2 | Val1e | Val2e | Val3e
&lt;BR /&gt;
&lt;BR /&gt;I have tried pivoting and unpivoting the rows but this does not allow me to keep the triplets together. Is it possible for me to send the input file through a Java script where I parse the file and output to a csv file in this format?
&lt;BR /&gt;Any help is much appreciated.</description>
    <pubDate>Sat, 16 Nov 2024 11:32:35 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-16T11:32:35Z</dc:date>
    <item>
      <title>[resolved] Transposing input file with dynamic number of columns</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312533#M83477</link>
      <description>I have a very tricky situation and have yet to come up with my own solution. I have an input csv file that has a dynamic number of columns and need to transpose this file to create a desired output file. The input file looks like this:
&lt;BR /&gt;
&lt;BR /&gt;ID1 | Units1 | Count | Val1a | Val2a | Val3a | Val1b | Val2b | Val3b | Val1c | Val2c | Val3c
&lt;BR /&gt;ID2 | Units2 | Count | Val1d | Val2d | Val3d | Val1e | Val2e | Val3e
&lt;BR /&gt;
&lt;BR /&gt;As you can see, the Val's are in triplets on each row and I need the triplets to stay together. The Count column holds a number of how many triplets are found on that row as each row is dynamic. The final output I need is:
&lt;BR /&gt;
&lt;BR /&gt;ID1 | Units1 | Val1a | Val2a | Val3a
&lt;BR /&gt;ID1 | Units1 | Val1b | Val2b | Val3b
&lt;BR /&gt;ID1 | Units1 | Val1c | Val2c | Val3c
&lt;BR /&gt;ID2 | Units2 | Val1d | Val2d | Val3d&amp;nbsp;
&lt;BR /&gt;ID2 | Units2 | Val1e | Val2e | Val3e
&lt;BR /&gt;
&lt;BR /&gt;I have tried pivoting and unpivoting the rows but this does not allow me to keep the triplets together. Is it possible for me to send the input file through a Java script where I parse the file and output to a csv file in this format?
&lt;BR /&gt;Any help is much appreciated.</description>
      <pubDate>Sat, 16 Nov 2024 11:32:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312533#M83477</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T11:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Transposing input file with dynamic number of columns</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312534#M83478</link>
      <description>Hi, 
&lt;BR /&gt;I tried similar in another post 
&lt;BR /&gt; 
&lt;A href="https://community.qlik.com/s/feed/0D53p00007vCqzrCAC" rel="nofollow noopener noreferrer"&gt;https://community.talend.com/t5/Design-and-Development/How-to-normalize-a-row-into-multiple-rows-from-the-names-of/td-p/112651&lt;/A&gt; 
&lt;BR /&gt;Pl check if you can get some idea from this. 
&lt;BR /&gt;vaibhav</description>
      <pubDate>Mon, 18 Aug 2014 12:25:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312534#M83478</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-18T12:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Transposing input file with dynamic number of columns</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312535#M83479</link>
      <description>I solved this by using the tJavaFlex component. My final component architecture was: 
&lt;BR /&gt;tFullInputRow --&amp;gt; tFlowToIterate --&amp;gt; tJavaFlex --&amp;gt; tOutputFileDelimited 
&lt;BR /&gt;My Java code was along the lines of 
&lt;BR /&gt; 
&lt;PRE&gt;// First we split the data on the delimiter of the file, assuming comma separated for now&lt;BR /&gt;String[] splitData =&amp;nbsp;((String)globalMap.get("input")).split("|");&lt;BR /&gt;// Initialise the three value strings&lt;BR /&gt;String value1 = ""&lt;BR /&gt;String value2 = ""&lt;BR /&gt;String value3 = ""&lt;BR /&gt;for (int i = 0; i &amp;lt; splitData.length; i++) {&lt;BR /&gt;    if (i == 1) {&lt;BR /&gt;        // id field is the first field&lt;BR /&gt;        String id = splitData&lt;I&gt;;&lt;BR /&gt;    } else if (i == 2) {&lt;BR /&gt;        unit field is the second field&lt;BR /&gt;        String unit = splitData&lt;I&gt;;&lt;BR /&gt;    } else if (i == 3) {&lt;BR /&gt;        // Don't need to do anything with the count data&lt;BR /&gt;    } else if (i % 3 == 1) {&lt;BR /&gt;        // value1 fields are 4, 7, 10 etc so modulo 3 == 1&lt;BR /&gt;        if (value1.length == 0) {&lt;BR /&gt;            value1 + splitData&lt;I&gt;;&lt;BR /&gt;        } else {&lt;BR /&gt;            // if the value field isn't empty (ie. for val1b) then we need to add a delimiter for further processing&lt;BR /&gt;            value1 + "|" + splitData&lt;I&gt;;&lt;BR /&gt;        }&lt;BR /&gt;    } else if (i % 3 == 1) {&lt;BR /&gt;        if (value2.length == 0) {&lt;BR /&gt;            value2 + splitData&lt;I&gt;;&lt;BR /&gt;        } else {&lt;BR /&gt;            value2 + "|" + splitData&lt;I&gt;;&lt;BR /&gt; }&lt;BR /&gt; } else if (i % 3 == 3) {&lt;BR /&gt; if (value3.length == 0) {&lt;BR /&gt; value3 + splitData&lt;I&gt;;&lt;BR /&gt; } else {&lt;BR /&gt; value3 + "|" + splitData&lt;I&gt;;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;for(int i = 0; i &amp;lt; splitData.length; ++i)&lt;BR /&gt;/////// MAIN CODE ///////////////////////&lt;BR /&gt;output_row.id = id;&lt;BR /&gt;output_row.unit = unit;&lt;BR /&gt;output_row.value1 = value1;&lt;BR /&gt;output_row.value2 = value2;&lt;BR /&gt;output_row.value3 = value3;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Aug 2014 14:52:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312535#M83479</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-18T14:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Transposing input file with dynamic number of columns</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312536#M83480</link>
      <description>That's great...&lt;BR /&gt;thanks for posting up here.&lt;BR /&gt;Thanks&lt;BR /&gt;vaibhav</description>
      <pubDate>Mon, 18 Aug 2014 14:58:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312536#M83480</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-18T14:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] Transposing input file with dynamic number of columns</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312537#M83481</link>
      <description>I solved this by using the tJavaFlex component. My final component architecture was: 
&lt;BR /&gt;tFullInputRow --&amp;gt; tFlowToIterate --&amp;gt; tJavaFlex --&amp;gt; tOutputFileDelimited 
&lt;BR /&gt;My Java code was along the lines of 
&lt;BR /&gt; 
&lt;PRE&gt;// First we split the data on the delimiter of the file, assuming comma separated for now&lt;BR /&gt;String[] splitData =&amp;nbsp;((String)globalMap.get("input")).split("|");&lt;BR /&gt;// Initialise the three value strings&lt;BR /&gt;String value1 = ""&lt;BR /&gt;String value2 = ""&lt;BR /&gt;String value3 = ""&lt;BR /&gt;for (int i = 0; i &amp;lt; splitData.length; i++) {&lt;BR /&gt;    if (i == 1) {&lt;BR /&gt;        // id field is the first field&lt;BR /&gt;        String id = splitData&lt;I&gt;;&lt;BR /&gt;    } else if (i == 2) {&lt;BR /&gt;        unit field is the second field&lt;BR /&gt;        String unit = splitData&lt;I&gt;;&lt;BR /&gt;    } else if (i == 3) {&lt;BR /&gt;        // Don't need to do anything with the count data&lt;BR /&gt;    } else if (i % 3 == 1) {&lt;BR /&gt;        // value1 fields are 4, 7, 10 etc so modulo 3 == 1&lt;BR /&gt;        if (value1.length == 0) {&lt;BR /&gt;            value1 + splitData&lt;I&gt;;&lt;BR /&gt;        } else {&lt;BR /&gt;            // if the value field isn't empty (ie. for val1b) then we need to add a delimiter for further processing&lt;BR /&gt;            value1 + "|" + splitData&lt;I&gt;;&lt;BR /&gt;        }&lt;BR /&gt;    } else if (i % 3 == 1) {&lt;BR /&gt;        if (value2.length == 0) {&lt;BR /&gt;            value2 + splitData&lt;I&gt;;&lt;BR /&gt;        } else {&lt;BR /&gt;            value2 + "|" + splitData&lt;I&gt;;&lt;BR /&gt; }&lt;BR /&gt; } else if (i % 3 == 3) {&lt;BR /&gt; if (value3.length == 0) {&lt;BR /&gt; value3 + splitData&lt;I&gt;;&lt;BR /&gt; } else {&lt;BR /&gt; value3 + "|" + splitData&lt;I&gt;;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;for(int i = 0; i &amp;lt; splitData.length; ++i)&lt;BR /&gt;/////// MAIN CODE ///////////////////////&lt;BR /&gt;output_row.id = id;&lt;BR /&gt;output_row.unit = unit;&lt;BR /&gt;output_row.value1 = value1;&lt;BR /&gt;output_row.value2 = value2;&lt;BR /&gt;output_row.value3 = value3;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Aug 2014 15:07:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-Transposing-input-file-with-dynamic-number-of-columns/m-p/2312537#M83481</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-08-18T15:07:42Z</dc:date>
    </item>
  </channel>
</rss>

