<?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 Re: split a key value table into multiple columns in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1935431#M77068</link>
    <description>&lt;P&gt;Thanks a lot guys for all your ideas &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt; and especially to &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/675"&gt;@MarcoWedel&lt;/a&gt; . Your solution worked like a charm, I went from 3 hours to less than 7 seconds in data reshaping &lt;span class="lia-unicode-emoji" title=":rocket:"&gt;🚀&lt;/span&gt;...that's what I call a huge improvement.&lt;/P&gt;
&lt;P&gt;You're all amazing guys!!!&lt;/P&gt;</description>
    <pubDate>Wed, 25 May 2022 12:39:59 GMT</pubDate>
    <dc:creator>egma</dc:creator>
    <dc:date>2022-05-25T12:39:59Z</dc:date>
    <item>
      <title>split a key value table into multiple columns</title>
      <link>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933673#M76909</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;After making a call to an external API I got the data into qlik sense in the format of KEY-VALUE pairs:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="egma_2-1653057462147.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/79954i77F933C111FC7FCF/image-size/large?v=v2&amp;amp;px=999" role="button" title="egma_2-1653057462147.png" alt="egma_2-1653057462147.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to transform this table into something like this where each row with the same key goes as the value of a separate column like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="egma_3-1653057810017.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/79956i75E7B3D44E4DE036/image-size/large?v=v2&amp;amp;px=999" role="button" title="egma_3-1653057810017.png" alt="egma_3-1653057810017.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried for loops, it works but is really slow (until 3 hours to reshape the data).&amp;nbsp; Do you have another approach to recommend me to unfold the data?&lt;/P&gt;
&lt;P&gt;Thanks in advance for any help or advice you can give me,&lt;/P&gt;
&lt;P&gt;Carlos&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 14:50:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933673#M76909</guid>
      <dc:creator>egma</dc:creator>
      <dc:date>2022-05-20T14:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: split a key value table into multiple columns</title>
      <link>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933805#M76913</link>
      <description>&lt;P&gt;for loops work great with small volumes but as youve found out its very slow.&amp;nbsp; table opertaions are much faster.&amp;nbsp; you can label your rows with row numbers, add an index to each value, and add a group.&lt;/P&gt;
&lt;P&gt;for example:&lt;BR /&gt;load &lt;BR /&gt;floor(rand()*1000) as volume,&lt;BR /&gt;&lt;SPAN&gt;rowno() as row, &lt;BR /&gt;floor(rowno()/5) as group, &lt;BR /&gt;mod(RowNo()-1,5) as order&lt;BR /&gt;&lt;/SPAN&gt;while iterno()&amp;lt;20;&lt;BR /&gt;load 1 autogenerate(1);&lt;/P&gt;
&lt;P&gt;you can event conver the order as values:&lt;BR /&gt;pick(mod(RowNo()-1,5)+1,'1st','2nd','3rd','4th','5th') as order&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_0-1653079061205.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/79981i967F420F9D223ABC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_0-1653079061205.png" alt="edwin_0-1653079061205.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can actually stop there and just lookup the value using set analysis&amp;nbsp;&lt;BR /&gt;{&amp;lt;order={'2nd'}&amp;gt;}&lt;BR /&gt;&lt;BR /&gt;if you still need to pivot the table you can aggregate it&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;t:&lt;BR /&gt;load floor(rand()*1000) as volume, rowno() as row, floor(rowno()/5) as group, &lt;BR /&gt;pick(mod(RowNo()-1,5)+1,'1st','2nd','3rd','4th','5th') as order &lt;BR /&gt;while iterno()&amp;lt;20;&lt;BR /&gt;load 1 autogenerate(1);&lt;/P&gt;
&lt;P&gt;NoConcatenate&lt;BR /&gt;temp:&lt;BR /&gt;load &lt;BR /&gt;[group], &lt;BR /&gt;if([order]='1st', (volume)) as first,&lt;BR /&gt;if([order]='2nd', (volume)) as sec,&lt;BR /&gt;if([order]='3rd', (volume)) as third,&lt;BR /&gt;if([order]='4th', (volume)) as fourth,&lt;BR /&gt;if([order]='5th', (volume)) as fifth&lt;BR /&gt;Resident t&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;NoConcatenate&lt;BR /&gt;d:&lt;BR /&gt;load &lt;BR /&gt;[group], &lt;BR /&gt;(max(first)) as first,&lt;BR /&gt;(max(sec)) as sec,&lt;BR /&gt;(max(third)) as third,&lt;BR /&gt;(max(fourth)) as fourth,&lt;BR /&gt;(max(fifth)) as fifth&lt;BR /&gt;Resident temp&lt;BR /&gt;group by [group]&lt;BR /&gt;;&lt;BR /&gt;drop table temp;&lt;BR /&gt;exit script;&lt;/P&gt;
&lt;P&gt;here is another way of pivoting:&lt;BR /&gt;&lt;A href="https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/td-p/1513761" target="_blank"&gt;https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/td-p/1513761&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 20:54:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933805#M76913</guid>
      <dc:creator>edwin</dc:creator>
      <dc:date>2022-05-20T20:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: split a key value table into multiple columns</title>
      <link>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933806#M76914</link>
      <description>&lt;P&gt;obviously you will modify it to use 7 as your divisor&lt;/P&gt;
&lt;P&gt;and this assumes the table is already in the right order&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 20:56:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933806#M76914</guid>
      <dc:creator>edwin</dc:creator>
      <dc:date>2022-05-20T20:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: split a key value table into multiple columns</title>
      <link>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933873#M76925</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;one solution might be as well:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MarcoWedel_0-1653129420300.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/79992i1F2DE798F8AE5586/image-size/large?v=v2&amp;amp;px=999" role="button" title="MarcoWedel_0-1653129420300.png" alt="MarcoWedel_0-1653129420300.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;mapFields:
Mapping
LOAD 'field'&amp;amp;RecNo(),
     Field 
Inline [
Field
URLid
URL
views
downloads
sessions
visitors
timeonpage
];

table1:
LOAD *, If(key=Previous(key),Peek(FieldNo)+1,1) as FieldNo
Inline [
key, value
1, URLid 1
1, URL 1
1, 10
1, 11
1, 12
1, 13
1, 14
2, URLid 2
2, URL 2
2, 20
2, 21
2, 22
2, 23
2, 24
3, URLid 3
3, URL 3
3, 30
3, 31
3, 32
3, 33
3, 34
];

table2:
Generic
LOAD key,
     'field'&amp;amp;FieldNo,
     value 
Resident table1;

DROP Table table1;

table3:
LOAD 1 as tempfield AutoGenerate 0;

FOR i = NoOfTables()-1 to 0 STEP -1
  LET vTable=TableName($(i));
  IF WildMatch('$(vTable)', 'table2.*') THEN
    JOIN ([table3]) LOAD * RESIDENT [$(vTable)];
    DROP TABLE [$(vTable)];
  ENDIF
NEXT i

DROP Field tempfield;

RENAME Fields using mapFields;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope this helps&lt;/P&gt;
&lt;P&gt;Marco&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2022 10:39:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1933873#M76925</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2022-05-21T10:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: split a key value table into multiple columns</title>
      <link>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1935431#M77068</link>
      <description>&lt;P&gt;Thanks a lot guys for all your ideas &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt; and especially to &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/675"&gt;@MarcoWedel&lt;/a&gt; . Your solution worked like a charm, I went from 3 hours to less than 7 seconds in data reshaping &lt;span class="lia-unicode-emoji" title=":rocket:"&gt;🚀&lt;/span&gt;...that's what I call a huge improvement.&lt;/P&gt;
&lt;P&gt;You're all amazing guys!!!&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 12:39:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/split-a-key-value-table-into-multiple-columns/m-p/1935431#M77068</guid>
      <dc:creator>egma</dc:creator>
      <dc:date>2022-05-25T12:39:59Z</dc:date>
    </item>
  </channel>
</rss>

