<?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 Script para converter registros de tabelas em colunas in Connectivity &amp; Data Prep</title>
    <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2103662#M12585</link>
    <description>&lt;P&gt;Olá estou tentando desenvolver um script de carga de dados com única tabela de produtos adicionando novas colunas com base no resultado de 2 tabelas (anexos e imagem_externa)&lt;/P&gt;
&lt;P&gt;De acordo com a figura, o modelo apresenta as tabelas onde cada produto pode ter até 3 registros de anexos e até 3 registros de url&lt;/P&gt;
&lt;P&gt;O resultado final seria uma tabela contendo os valores de ambas as tabelas anexos e imagem_externa concatenados em uma única linha com a tabela produto&lt;/P&gt;
&lt;TABLE border="1" width="63.99932273373943%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="10%" height="69px"&gt;id&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;nome&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;anexo_1&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;anexo_2&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;anexo_3&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;url_1&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;url_2&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;url_3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2023-08-08 at 14.54.04.png" style="width: 522px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/113859i0A2605C7E59E9F36/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2023-08-08 at 14.54.04.png" alt="Screen Shot 2023-08-08 at 14.54.04.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 18:08:29 GMT</pubDate>
    <dc:creator>marciomgm</dc:creator>
    <dc:date>2023-08-08T18:08:29Z</dc:date>
    <item>
      <title>Script para converter registros de tabelas em colunas</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2103662#M12585</link>
      <description>&lt;P&gt;Olá estou tentando desenvolver um script de carga de dados com única tabela de produtos adicionando novas colunas com base no resultado de 2 tabelas (anexos e imagem_externa)&lt;/P&gt;
&lt;P&gt;De acordo com a figura, o modelo apresenta as tabelas onde cada produto pode ter até 3 registros de anexos e até 3 registros de url&lt;/P&gt;
&lt;P&gt;O resultado final seria uma tabela contendo os valores de ambas as tabelas anexos e imagem_externa concatenados em uma única linha com a tabela produto&lt;/P&gt;
&lt;TABLE border="1" width="63.99932273373943%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="10%" height="69px"&gt;id&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;nome&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;anexo_1&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;anexo_2&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;anexo_3&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;url_1&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;url_2&lt;/TD&gt;
&lt;TD width="10%" height="69px"&gt;url_3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2023-08-08 at 14.54.04.png" style="width: 522px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/113859i0A2605C7E59E9F36/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2023-08-08 at 14.54.04.png" alt="Screen Shot 2023-08-08 at 14.54.04.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 18:08:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2103662#M12585</guid>
      <dc:creator>marciomgm</dc:creator>
      <dc:date>2023-08-08T18:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Script para converter registros de tabelas em colunas</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2103697#M12588</link>
      <description>&lt;P&gt;Hi, to convert records into columns you must use the Cross Table.&lt;BR /&gt;Here is a URL that explains it with examples:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/crosstable.htm" target="_blank"&gt;https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/crosstable.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarts.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 20:08:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2103697#M12588</guid>
      <dc:creator>cristianj23a</dc:creator>
      <dc:date>2023-08-08T20:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Script para converter registros de tabelas em colunas</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2104207#M12597</link>
      <description>&lt;P&gt;You can solve this using join considering the fields starting with __Key are sequential for each unique id. see the following example:&lt;/P&gt;
&lt;P&gt;anexos:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;id&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;anexo&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;__KEY_produto&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;3461&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;f02kr093f930fk3k&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;3461&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;vvopsdmvpvmpos&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;3461&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;vldspvsdvm&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;6524&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;ddvvsvsvdsv&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can solve this using a sequence os joins with a filter and to have a code more flexible and add more colums, the join is inside a for loop.&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;anexo:
load * inline [
id,anexo,__KEY_produto
3461, f02kr093f930fk3k , 1
3461, vvopsdmvpvmpos,2
3461, vldspvsdvm,3
6524, ddvvsvsvdsv, 1
1524, c9s0c90s, 1
];


Produto:
Load  * inline [
id, nome, codigo
3461, prod1 , A124
6524, prod2, B4560
1524, prod3 ,CA124
];

for vkey =  1 to 3 
  Left Join (Produto)
  Load id, anexo as anexo_$(vkey)
  Resident anexo
  where __KEY_produto = $(vkey);
next vkey;


drop table anexo;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;This will be the final result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="resultado unpivot.png" style="width: 611px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/114000i31D8238316072B9B/image-size/large?v=v2&amp;amp;px=999" role="button" title="resultado unpivot.png" alt="resultado unpivot.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps anyone else with similar use case.&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Pablo&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 17:54:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Script-para-converter-registros-de-tabelas-em-colunas/m-p/2104207#M12597</guid>
      <dc:creator>pablolabbe</dc:creator>
      <dc:date>2023-08-09T17:54:05Z</dc:date>
    </item>
  </channel>
</rss>

