<?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 how to pivot in load script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513761#M36601</link>
    <description>&lt;P&gt;I am working in Qlik Sense Enterprise 3.2.&amp;nbsp; I have a data source that looks like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Test:&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;Inline&lt;BR /&gt;[&lt;BR /&gt;Key, State&lt;BR /&gt;1, a&lt;BR /&gt;1, a&lt;BR /&gt;1, b&lt;BR /&gt;2, a&lt;BR /&gt;3, c&lt;BR /&gt;3, d&lt;BR /&gt;3, d&lt;BR /&gt;]&lt;BR /&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Within the load editor, I want to pivot this table on Key, turning my State values into column headers, whose values are populated by a count of Key.&amp;nbsp; So, I want my output to look like:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Key&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp;c&amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;How can I achieve this output in the load editor?&amp;nbsp; I don't think CrossTable or Generic will work.&amp;nbsp; CrossTable is a simple transposition (lacking the aggregation that I want) of a wide table into a tall table (which is the opposite direction of what I want).&amp;nbsp; Generic does turn a tall table into a wide table (which is the direction that I want), but it's a simple transposition (again, no aggregation).&amp;nbsp; In Excel or SQL, I would pivot the data.&amp;nbsp; However, I cannot perform this transformation outside of Qlik Sense.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Dec 2021 18:19:25 GMT</pubDate>
    <dc:creator>skyline01</dc:creator>
    <dc:date>2021-12-23T18:19:25Z</dc:date>
    <item>
      <title>how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513761#M36601</link>
      <description>&lt;P&gt;I am working in Qlik Sense Enterprise 3.2.&amp;nbsp; I have a data source that looks like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Test:&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;Inline&lt;BR /&gt;[&lt;BR /&gt;Key, State&lt;BR /&gt;1, a&lt;BR /&gt;1, a&lt;BR /&gt;1, b&lt;BR /&gt;2, a&lt;BR /&gt;3, c&lt;BR /&gt;3, d&lt;BR /&gt;3, d&lt;BR /&gt;]&lt;BR /&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Within the load editor, I want to pivot this table on Key, turning my State values into column headers, whose values are populated by a count of Key.&amp;nbsp; So, I want my output to look like:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Key&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp;c&amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;How can I achieve this output in the load editor?&amp;nbsp; I don't think CrossTable or Generic will work.&amp;nbsp; CrossTable is a simple transposition (lacking the aggregation that I want) of a wide table into a tall table (which is the opposite direction of what I want).&amp;nbsp; Generic does turn a tall table into a wide table (which is the direction that I want), but it's a simple transposition (again, no aggregation).&amp;nbsp; In Excel or SQL, I would pivot the data.&amp;nbsp; However, I cannot perform this transformation outside of Qlik Sense.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 18:19:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513761#M36601</guid>
      <dc:creator>skyline01</dc:creator>
      <dc:date>2021-12-23T18:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513770#M36606</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;&lt;PRE&gt;Test:
LOAD * INLINE [
    Key, State
    1, a
    1, a
    1, b
    2, a
    3, c
    3, d
    3, d
];

Left Join (Test)
LOAD Key,
	 State,
	 Count(State) as Count
Resident Test
Group By Key, State;

FinalTable:
LOAD DISTINCT Key
Resident Test;

FOR i = 1 to FieldValueCount('State')

	LET vState = FieldValue('State', $(i));
	
	Left Join (FinalTable)
	LOAD DISTINCT Key,
		 Count as [$(vState)]
	Resident Test
	Where State = '$(vState)';
	
NEXT

DROP Table Test;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 16:41:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513770#M36606</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-11-28T16:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513773#M36607</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Generic 
Load *,count(Key) as Dummy
Inline
[
Key, State
1, a
1, a
1, b
2, a
3, c
3, d
3, d
]
Group by Key,State;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 16:43:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513773#M36607</guid>
      <dc:creator>Frank_Hartmann</dc:creator>
      <dc:date>2018-11-28T16:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513777#M36608</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/29675"&gt;@Frank_Hartmann&lt;/a&gt;&lt;/P&gt;&lt;P&gt;That solution seems to be incomplete.&amp;nbsp; I need the output to be a single table.&amp;nbsp; That solution breaks up the output into separate tables, organized by non-zero State counts.&amp;nbsp; I might be able to re-shape it back into 1 table, though.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 16:57:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513777#M36608</guid>
      <dc:creator>skyline01</dc:creator>
      <dc:date>2018-11-28T16:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513779#M36610</link>
      <description>&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/46628"&gt;@sunny_talwar&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Your solution works.&amp;nbsp; However, that seems to be a lot of code for something that seems pretty simple (e.g., I can do this with just a few lines in SQL).&amp;nbsp; Is your solution&amp;nbsp;the usual way to resolve this kind of situation?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 16:57:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513779#M36610</guid>
      <dc:creator>skyline01</dc:creator>
      <dc:date>2018-11-28T16:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513781#M36611</link>
      <description>It is not, the usual way is to use generic load.... but to combine them into a single table... one way or the other... you will need to use loop &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 28 Nov 2018 17:01:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513781#M36611</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-11-28T17:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513784#M36612</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/39496"&gt;@skyline01&lt;/a&gt;&lt;/P&gt;&lt;P&gt;We can do it with one expression of 10 characters in a pivot table object. And that's exactly where you should do this kind of thing if you're using Qlik Sense.&amp;nbsp;Why do you need to do this in the load script?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Qlik Sense is quite versatile, but&amp;nbsp;some kind of data transformation tricks can be executed by other specialist data munging tools with less lines of code. If you can do it in a couple of lines of sql then why don't you. Qlik Sense is perfectly capable of sending such a statement to a rdbms and receiving the results.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;BR /&gt;Gysbert&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 17:04:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513784#M36612</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2018-11-28T17:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513787#M36613</link>
      <description>Very well said</description>
      <pubDate>Wed, 28 Nov 2018 17:06:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513787#M36613</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-11-28T17:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513851#M36621</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/18624"&gt;@Gysbert_Wassenaar&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I know this can be done fairly easily in a visualization (if that is what you mean by "pivot table object").&amp;nbsp; I need it done in a load script since it's actually a working / intermediate table for a table that I eventually load into the model.&amp;nbsp; (In reality, I will be first joining 2 tables, pivoting the result, creating a calculated column, filtering the result, and then joining the result to yet another table.&amp;nbsp; I only need to load this final derived table into the model.)&lt;/P&gt;&lt;P&gt;And, in general, I would push down this kind of transformation into the database.&amp;nbsp; My problem is that I have severe querying restrictions put onto me by the DBAs of the data source.&amp;nbsp; (The actual source is ServiceNow, and I'm running this against a large table.&amp;nbsp; The only connection mechanism that I have available to me is ODBC, which is incredibly slow.&amp;nbsp; So, the DBAs want me to only run very simple and highly filtered queries, i.e., I can't run a pivot.)&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 18:37:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513851#M36621</guid>
      <dc:creator>skyline01</dc:creator>
      <dc:date>2018-11-28T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513856#M36623</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/39496"&gt;@skyline01&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thanks for explaining&amp;nbsp;the situation. I understand the&amp;nbsp;constraints&amp;nbsp;you have to work with. Unfortunately I don't have a better solution than&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/46628"&gt;@sunny_talwar&lt;/a&gt;&amp;nbsp;posted already. I hope it works for you.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;BR /&gt;Gysbert&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 19:01:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1513856#M36623</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2018-11-28T19:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to pivot in load script</title>
      <link>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1514428#M36671</link>
      <description>&lt;P&gt;Here's another alternative:&lt;/P&gt;&lt;PRE&gt;Test:
Load *		
Inline
[
Key, State
1, a
1, a
1, b
2, a
3, c
3, d
3, d
]
;

LET vFieldList = '';

For i = 1 to FieldValueCount('State')

	LET vField = FieldValue('State',$(i));
	LET vFieldList = '$(vFieldList), count(if(State=' &amp;amp; chr(39) &amp;amp; '$(vField)'  &amp;amp; chr(39) &amp;amp; ', [State])) as [$(vField)]';

Next


Result:
LOAD
	Key $(vFieldList)
Resident
	Test
Group By
	Key
	;		&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This might work a bit faster on larger data sets or if you have a lot of State values.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 17:09:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/how-to-pivot-in-load-script/m-p/1514428#M36671</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2018-11-29T17:09:46Z</dc:date>
    </item>
  </channel>
</rss>

