<?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: Converting to a crosstable in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865871#M1216319</link>
    <description>&lt;P&gt;Hi Marco,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you, really appreciate that&lt;/P&gt;</description>
    <pubDate>Thu, 02 Dec 2021 09:07:06 GMT</pubDate>
    <dc:creator>QlikMo</dc:creator>
    <dc:date>2021-12-02T09:07:06Z</dc:date>
    <item>
      <title>Converting to a crosstable</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865430#M1216296</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need some help converting my data to a cross table format.&lt;/P&gt;
&lt;P&gt;I have a data source with a list of prices. For each supplier / item combination I need to create a row with the last five prices as columns&lt;/P&gt;
&lt;P&gt;This is the example source data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LOAD * INLINE [
    Item, EffectiveDate, Price, Supplier
    Screw001, 15/11/2021, 500, S00100
    Screw001, 01/06/2021, 480, S00100
    Screw001, 02/04/2021, 475, S00100
    Screw001, 01/01/2021, 470, S00100
    Nut001, 10/10/2021, 200, S00352
    Nut001, 01/10/2021, 199, S00352
    Nut001, 02/05/2020, 170, S00352
    Bolt001, 16/09/2021, 15, S00421
    Bolt001, 14/02/2021, 14, S00421
    Bolt001, 01/02/2021, 14, S00421
    Bolt001, 01/12/2020, 12, S00421
    Bolt001, 06/06/2020, 10, S00421
    Bolt001, 01/01/2020, 5, S00421
    Screw001, 01/11/2020, 450, S00200
];&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would be the expected output.&lt;/P&gt;
&lt;TABLE width="1085px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="150.891px"&gt;%ItemSupplierKey&lt;/TD&gt;
&lt;TD width="74.8906px"&gt;Current Price&lt;/TD&gt;
&lt;TD width="104.859px"&gt;Current Effective Date&lt;/TD&gt;
&lt;TD width="87.8594px"&gt;Previous Price&lt;/TD&gt;
&lt;TD width="111.797px"&gt;Previous Effective Date&lt;/TD&gt;
&lt;TD width="68.8281px"&gt;Third Price&lt;/TD&gt;
&lt;TD width="110.812px"&gt;Third Effective Date&lt;/TD&gt;
&lt;TD width="85.7812px"&gt;Fourth Price&lt;/TD&gt;
&lt;TD width="125.703px"&gt;Fourth Effective Date&lt;/TD&gt;
&lt;TD width="76.7656px"&gt;Fifth Price&lt;/TD&gt;
&lt;TD width="85.8125px"&gt;Fifth Effective Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="150.891px"&gt;Screw001|S00100&lt;/TD&gt;
&lt;TD width="74.8906px"&gt;500&lt;/TD&gt;
&lt;TD width="104.859px"&gt;15/11/2021&lt;/TD&gt;
&lt;TD width="87.8594px"&gt;480&lt;/TD&gt;
&lt;TD width="111.797px"&gt;01/06/2021&lt;/TD&gt;
&lt;TD width="68.8281px"&gt;475&lt;/TD&gt;
&lt;TD width="110.812px"&gt;02/04/2021&lt;/TD&gt;
&lt;TD width="85.7812px"&gt;470&lt;/TD&gt;
&lt;TD width="125.703px"&gt;01/01/2021&lt;/TD&gt;
&lt;TD width="76.7656px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="85.8125px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="150.891px"&gt;Nut001|S00352&lt;/TD&gt;
&lt;TD width="74.8906px"&gt;200&lt;/TD&gt;
&lt;TD width="104.859px"&gt;10/10/2021&lt;/TD&gt;
&lt;TD width="87.8594px"&gt;199&lt;/TD&gt;
&lt;TD width="111.797px"&gt;01/10/2021&lt;/TD&gt;
&lt;TD width="68.8281px"&gt;170&lt;/TD&gt;
&lt;TD width="110.812px"&gt;02/05/2020&lt;/TD&gt;
&lt;TD width="85.7812px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="125.703px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="76.7656px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="85.8125px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="150.891px"&gt;Bolt001|S00421&lt;/TD&gt;
&lt;TD width="74.8906px"&gt;15&lt;/TD&gt;
&lt;TD width="104.859px"&gt;16/09/2021&lt;/TD&gt;
&lt;TD width="87.8594px"&gt;14&lt;/TD&gt;
&lt;TD width="111.797px"&gt;14/02/2021&lt;/TD&gt;
&lt;TD width="68.8281px"&gt;14&lt;/TD&gt;
&lt;TD width="110.812px"&gt;01/02/2021&lt;/TD&gt;
&lt;TD width="85.7812px"&gt;12&lt;/TD&gt;
&lt;TD width="125.703px"&gt;01/12/2020&lt;/TD&gt;
&lt;TD width="76.7656px"&gt;10&lt;/TD&gt;
&lt;TD width="85.8125px"&gt;06/06/2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="150.891px"&gt;Screw001|S00200&lt;/TD&gt;
&lt;TD width="74.8906px"&gt;450&lt;/TD&gt;
&lt;TD width="104.859px"&gt;01/11/2020&lt;/TD&gt;
&lt;TD width="87.8594px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="111.797px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="68.8281px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="110.812px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="85.7812px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="125.703px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="76.7656px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="85.8125px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes - only the five most recent prices should be used (EffectiveDate) by Item and Supplier. Bolt001 has 6 prices so the last one should not be shown&lt;/P&gt;
&lt;P&gt;Also an item can have multiple suppliers e.g. Item Screw001. These should show as separate rows&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate any help on this. I've not done this before in Qlikview. Normally I use the crosstable function to covert these types of tables to a row format. I started off with loops but this took a long time in the load script. I then started looking at generic load but I am struggling with that too. I would really appreciate any tips or input&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 13:38:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865430#M1216296</guid>
      <dc:creator>QlikMo</dc:creator>
      <dc:date>2021-12-01T13:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a crosstable</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865541#M1216304</link>
      <description>&lt;P&gt;I think progress has been made using the Autonumber function twice. I just need to figure out how to get the rows to merge rather than a new row and then I am pretty much there.&lt;/P&gt;
&lt;P&gt;I am not sure if this is the most efficient method so I welcome any feedback.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QlikMo_0-1638368598270.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/67741i7EB975B0A610E1A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="QlikMo_0-1638368598270.png" alt="QlikMo_0-1638368598270.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Prices:
LOAD * INLINE [
    Item, EffectiveDate, Price, Supplier
    Screw001, 15/11/2021, 500, S00100
    Screw001, 01/06/2021, 480, S00100
    Screw001, 02/04/2021, 475, S00100
    Screw001, 01/01/2021, 470, S00100
    Nut001, 10/10/2021, 200, S00352
    Nut001, 01/10/2021, 199, S00352
    Nut001, 02/05/2020, 170, S00352
    Bolt001, 16/09/2021, 15, S00421
    Bolt001, 14/02/2021, 14, S00421
    Bolt001, 01/02/2021, 14, S00421
    Bolt001, 01/12/2020, 12, S00421
    Bolt001, 06/06/2020, 10, S00421
    Bolt001, 01/01/2020, 5, S00421
    Screw001, 01/11/2020, 450, S00200
];



New:
LOAD *, (Item &amp;amp;'|' &amp;amp; Supplier) as %ItemSupplierKey, autonumber(Item &amp;amp;'|' &amp;amp; Supplier) as ID
RESIDENT Prices
order by Item, Supplier, EffectiveDate DESC;

drop table Prices;


New2:
LOAD *, Autonumber(RowNo(),ID) as ID2
RESIDENT New;

drop table New;


NoConcatenate
New3:
LOAD *
RESIDENT New2 where ID2 &amp;lt;= '5';

Drop table New2;



Final:

LOAD
 %ItemSupplierKey, 
if(ID2 = 1, Price) as [Current Price],
if(ID2 = 2, Price) as [Previous Price],
if(ID2 = 3, Price) as [Third Price],
if(ID2 = 4, Price) as [Fourth Price],
if(ID2 = 5, Price) as [Fifth Price]

RESIDENT New3;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 14:25:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865541#M1216304</guid>
      <dc:creator>QlikMo</dc:creator>
      <dc:date>2021-12-01T14:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a crosstable</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865670#M1216313</link>
      <description>&lt;P&gt;Could anyone help me with the 'Final' section in the previously posted code?&lt;/P&gt;
&lt;P&gt;I am struggling to merge the rows when the %ItemSupplierKey is the same. I have tried quite a few things but no luck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I need to convert it from this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QlikMo_0-1638380589825.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/67758iCC3C9DC061E853DB/image-size/large?v=v2&amp;amp;px=999" role="button" title="QlikMo_0-1638380589825.png" alt="QlikMo_0-1638380589825.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;to this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QlikMo_1-1638380612697.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/67759iA24B84E69F02C031/image-size/large?v=v2&amp;amp;px=999" role="button" title="QlikMo_1-1638380612697.png" alt="QlikMo_1-1638380612697.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried things&amp;nbsp; below&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Final:
LOAD
 %ItemSupplierKey, 
if(ID2 = 1, Price) as [Current Price] 
RESIDENT New3;
 
LOAD
 %ItemSupplierKey, 
if(ID2 = 2, Price) as [Previous Price]
RESIDENT New3
where len(Price) &amp;gt; 0;

LOAD
 %ItemSupplierKey, 
if(ID2 = 3, Price) as [Third Price]
RESIDENT New3
where len(Price) &amp;gt; 0;

LOAD
 %ItemSupplierKey,
if(ID2 = 4, Price) as [Fourth Price]
RESIDENT New3
where len(Price) &amp;gt; 0;

LOAD
 %ItemSupplierKey,
if(ID2 = 5, Price) as [Fifth Price]
RESIDENT New3
where len(Price) &amp;gt; 0;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and also using joins, concatenates etc. with no luck. I also thought about adding the null columns in each load in the hope it joins&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Final:
LOAD
 %ItemSupplierKey, 
if(ID2 = 1, Price) as [Current Price], null() as [Previous Price], null() as [Third Price], null() as [Fourth Price], null() as [Fifth Price]  
RESIDENT New3;

//Concatenate
//join (Final)
inner join (Final)
 
LOAD
 %ItemSupplierKey, 
if(ID2 = 2, Price) as [Previous Price],  null() as [Third Price], null() as [Fourth Price], null() as [Fifth Price], null()as [Current Price]
RESIDENT New3
where len(Price) &amp;gt; 0;

//Concatenate
//join (Final)
inner join (Final)
 
LOAD
 %ItemSupplierKey, 
if(ID2 = 3, Price) as [Third Price],  null() as [Fourth Price], null() as [Fifth Price], null() as [Current Price], null() as [Previous Price]
RESIDENT New3
where len(Price) &amp;gt; 0;

//Concatenate
//join (Final)
inner join (Final)

LOAD
 %ItemSupplierKey,
if(ID2 = 4, Price) as [Fourth Price],  null() as [Fifth Price], null() as [Current Price], null() as [Previous Price], null() as [Third Price]
RESIDENT New3
where len(Price) &amp;gt; 0;

//Concatenate
//join (Final)
inner join (Final)

LOAD
 %ItemSupplierKey,
if(ID2 = 5, Price) as [Fifth Price], null() as [Current Price], null() as [Previous Price], null() as [Third Price], null() as [Fourth Price]
RESIDENT New3
where len(Price) &amp;gt; 0;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 17:51:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865670#M1216313</guid>
      <dc:creator>QlikMo</dc:creator>
      <dc:date>2021-12-01T17:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a crosstable</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865754#M1216317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;one solution using a generic load like you initially seem to have tried as well:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MarcoWedel_0-1638397745041.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/67771i53E182DBB9BCF9D7/image-size/large?v=v2&amp;amp;px=999" role="button" title="MarcoWedel_0-1638397745041.png" alt="MarcoWedel_0-1638397745041.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;table1:
LOAD Item&amp;amp;'|'&amp;amp;Supplier as %ItemSupplierKey,
     EffectiveDate,
     Price
INLINE [
    Item, EffectiveDate, Price, Supplier
    Screw001, 15/11/2021, 500, S00100
    Screw001, 01/06/2021, 480, S00100
    Screw001, 02/04/2021, 475, S00100
    Screw001, 01/01/2021, 470, S00100
    Nut001, 10/10/2021, 200, S00352
    Nut001, 01/10/2021, 199, S00352
    Nut001, 02/05/2020, 170, S00352
    Bolt001, 16/09/2021, 15, S00421
    Bolt001, 14/02/2021, 14, S00421
    Bolt001, 01/02/2021, 14, S00421
    Bolt001, 01/12/2020, 12, S00421
    Bolt001, 06/06/2020, 10, S00421
    Bolt001, 01/01/2020, 5, S00421
    Screw001, 01/11/2020, 450, S00200
];

table2:
LOAD *,
     Pick(AutoNumber(EffectiveDate,%ItemSupplierKey),'Current','Previous','Third','Fourth','Fifth') as Sequence
Resident table1
Where AutoNumber(EffectiveDate,%ItemSupplierKey)&amp;lt;6
Order By EffectiveDate Desc;

tabPrice:
Generic
LOAD %ItemSupplierKey,
     Sequence&amp;amp;' Price',
     Price
Resident table2;

tabEffDate:
Generic
LOAD %ItemSupplierKey,
     Sequence&amp;amp;' Effective Date',
     EffectiveDate
Resident table2;

DROP Tables table1, table2;

tabFinal:
LOAD '' as TempField AutoGenerate 0;

FOR i = NoOfTables()-1 to 0 STEP -1
  LET vTable=TableName($(i));
  IF WildMatch('$(vTable)','tabPrice.*','tabEffDate.*') THEN
    Join (tabFinal) LOAD * Resident [$(vTable)];
    DROP Table [$(vTable)];
  ENDIF
NEXT i

DROP Field TempField;&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>Wed, 01 Dec 2021 22:29:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865754#M1216317</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2021-12-01T22:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a crosstable</title>
      <link>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865871#M1216319</link>
      <description>&lt;P&gt;Hi Marco,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you, really appreciate that&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 09:07:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Converting-to-a-crosstable/m-p/1865871#M1216319</guid>
      <dc:creator>QlikMo</dc:creator>
      <dc:date>2021-12-02T09:07:06Z</dc:date>
    </item>
  </channel>
</rss>

