<?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: Consolidating multiple sales records into a single line in a table in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980782#M80940</link>
    <description>&lt;P&gt;As below&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;temp:
load *,recno() as rowID inline [ 
CustomerID,ProductCode,SalesDate
1,x,2020
1,x,2021
1,y,2022
1,x,2022
2,x,2019
2,p,2021
2,y,2022
3,q,2005
3,q,2021
3,p,2022
4,y,2021
4,p,2021
];

Summary:
Load 
*,
if(GroupA&amp;gt;0 and GroupB&amp;gt;0,1,0) as isBoth
;
Load CustomerID
,count(if(WildMatch(ProductCode,'x','y'),1)) as GroupA
,count(if(WildMatch(ProductCode,'p','q'),1)) as GroupB
Resident temp
Group by CustomerID;

exit Script;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 702px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/89061iE67F091787D1D73A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.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>Wed, 14 Sep 2022 08:41:25 GMT</pubDate>
    <dc:creator>vinieme12</dc:creator>
    <dc:date>2022-09-14T08:41:25Z</dc:date>
    <item>
      <title>Consolidating multiple sales records into a single line in a table</title>
      <link>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980607#M80921</link>
      <description>&lt;P&gt;I have a sales dataset with columns CustomerID, ProductCode, and SalesDate. Each line has a different combination of these variables.&lt;/P&gt;
&lt;P&gt;Each ProductCode can be categorized into one of two groups. Let's call them Group A and Group B.&lt;/P&gt;
&lt;P&gt;I want to organize a new table with four columns: CustomerID, isGroupA, isGroupB, and isBoth.&lt;/P&gt;
&lt;P&gt;Each line should be associated with a unique CustomerID, with counts of total purchases of Group A products in isGroupA, a count of total purchases of Group B products in isGroupB, and, if the values of isGroupA and isGroupB are both greater than zero, a boolean value of 1 in isBoth.&lt;/P&gt;
&lt;P&gt;So far, we have tried using the Distinct keyword in association with the CustomerID column, using the variables as dimensions (rather than measures), as well as a number of more complicated recommendations for similar puzzles found on the Qlik community boards.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Current Table:&lt;/U&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;CustomerID&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;ProductCode&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;SalesDate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;1&lt;/TD&gt;
&lt;TD height="25px"&gt;x&lt;/TD&gt;
&lt;TD height="25px"&gt;2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;1&lt;/TD&gt;
&lt;TD height="25px"&gt;x&lt;/TD&gt;
&lt;TD height="25px"&gt;2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;1&lt;/TD&gt;
&lt;TD height="25px"&gt;y&lt;/TD&gt;
&lt;TD height="25px"&gt;2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;1&lt;/TD&gt;
&lt;TD height="25px"&gt;x&lt;/TD&gt;
&lt;TD height="25px"&gt;2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;2&lt;/TD&gt;
&lt;TD height="25px"&gt;x&lt;/TD&gt;
&lt;TD height="25px"&gt;2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;2&lt;/TD&gt;
&lt;TD height="25px"&gt;p&lt;/TD&gt;
&lt;TD height="25px"&gt;2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;2&lt;/TD&gt;
&lt;TD height="25px"&gt;y&lt;/TD&gt;
&lt;TD height="25px"&gt;2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;3&lt;/TD&gt;
&lt;TD height="25px"&gt;q&lt;/TD&gt;
&lt;TD height="25px"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;3&lt;/TD&gt;
&lt;TD height="25px"&gt;q&lt;/TD&gt;
&lt;TD height="25px"&gt;2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;3&lt;/TD&gt;
&lt;TD height="25px"&gt;p&lt;/TD&gt;
&lt;TD height="25px"&gt;2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;4&lt;/TD&gt;
&lt;TD height="25px"&gt;y&lt;/TD&gt;
&lt;TD height="25px"&gt;2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="25px"&gt;4&lt;/TD&gt;
&lt;TD height="25px"&gt;p&lt;/TD&gt;
&lt;TD height="25px"&gt;2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Group A: [x,y]&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Group B: [p,q]&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Desired Table:&lt;/U&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;CustomerID&lt;/TD&gt;
&lt;TD width="25%"&gt;isGroupA&lt;/TD&gt;
&lt;TD width="25%"&gt;isGroupB&lt;/TD&gt;
&lt;TD width="25%"&gt;isBoth&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;TD width="25%"&gt;4&lt;/TD&gt;
&lt;TD width="25%"&gt;0&lt;/TD&gt;
&lt;TD width="25%"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;2&lt;/TD&gt;
&lt;TD width="25%"&gt;2&lt;/TD&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;3&lt;/TD&gt;
&lt;TD width="25%"&gt;0&lt;/TD&gt;
&lt;TD width="25%"&gt;3&lt;/TD&gt;
&lt;TD width="25%"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;4&lt;/TD&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;TD width="25%"&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;&lt;STRONG&gt;How do I count and consolidate the multiple sales records for each customer into one row?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 20:15:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980607#M80921</guid>
      <dc:creator>mcorser</dc:creator>
      <dc:date>2022-09-13T20:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidating multiple sales records into a single line in a table</title>
      <link>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980703#M80930</link>
      <description>&lt;P&gt;Hi, one way would be like this:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;data:
LOAD *,
CustomerID	&amp;amp; '|' &amp;amp; SalesDate as cust_date.#key,
ProductCode	&amp;amp; '|' &amp;amp; SalesDate as counter
INLINE [
CustomerID|ProductCode|SalesDate
1|x|2020
1|x|2021
1|y|2022
1|x|2022
2|x|2019
2|p|2021
2|y|2022
3|q|2005
3|q|2021
3|p|2022
4|y|2021
4|p|2021
] (DELIMITER IS '|');

temp_calc:
LOAD
CustomerID,
[cust_date.#key],
ProductCode,
counter
RESIDENT data;

LEFT JOIN (temp_calc)
LOAD * INLINE [
ProductCode|GroupCode
x|A
y|A
p|B
q|B
] (DELIMITER IS '|');

temp_calc2:
LOAD
CustomerID,
GroupCode,
COUNT(DISTINCT counter) AS count_of_counter
RESIDENT temp_calc
GROUP BY CustomerID,GroupCode;

DROP TABLE temp_calc;

temp_conc:
LOAD DISTINCT
CustomerID
RESIDENT temp_calc2;

JOIN (temp_conc)
LOAD
SUBFIELD('A|B','|') AS GroupCode
AUTOGENERATE 1;

CONCATENATE (temp_calc2)
LOAD *,
0 AS count_of_counter
RESIDENT temp_conc;

DROP TABLE temp_conc;

temp_final:
LOAD DISTINCT
CustomerID
RESIDENT temp_calc2;

LEFT JOIN (temp_final)
LOAD
CustomerID,
RANGESUM(SUM(count_of_counter),0) AS isGroupA
RESIDENT temp_calc2
WHERE MATCH(GroupCode,'A')
GROUP BY CustomerID;

LEFT JOIN (temp_final)
LOAD
CustomerID,
RANGESUM(SUM(count_of_counter),0) AS isGroupB
RESIDENT temp_calc2
WHERE MATCH(GroupCode,'B')
GROUP BY CustomerID;

DROP TABLE temp_calc2;

final:
LOAD *,
PICK(MATCH(RANGESUM(isGroupA*isGroupB,0),0)+1,1,0) AS isBoth
RESIDENT temp_final;

DROP TABLE temp_final;

DROP FIELDS counter,[cust_date.#key];
&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 14 Sep 2022 06:02:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980703#M80930</guid>
      <dc:creator>RsQK</dc:creator>
      <dc:date>2022-09-14T06:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidating multiple sales records into a single line in a table</title>
      <link>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980782#M80940</link>
      <description>&lt;P&gt;As below&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;temp:
load *,recno() as rowID inline [ 
CustomerID,ProductCode,SalesDate
1,x,2020
1,x,2021
1,y,2022
1,x,2022
2,x,2019
2,p,2021
2,y,2022
3,q,2005
3,q,2021
3,p,2022
4,y,2021
4,p,2021
];

Summary:
Load 
*,
if(GroupA&amp;gt;0 and GroupB&amp;gt;0,1,0) as isBoth
;
Load CustomerID
,count(if(WildMatch(ProductCode,'x','y'),1)) as GroupA
,count(if(WildMatch(ProductCode,'p','q'),1)) as GroupB
Resident temp
Group by CustomerID;

exit Script;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 702px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/89061iE67F091787D1D73A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.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>Wed, 14 Sep 2022 08:41:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Consolidating-multiple-sales-records-into-a-single-line-in-a/m-p/1980782#M80940</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-09-14T08:41:25Z</dc:date>
    </item>
  </channel>
</rss>

