<?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: Compare values within a customer group / pivot table columns in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1965475#M79569</link>
    <description>&lt;P&gt;Assuming that You have a table like this:&lt;/P&gt;
&lt;P&gt;Load * Inline [&lt;BR /&gt;Product, Customer, Discount&lt;BR /&gt;Prod1,Cust1,10&lt;BR /&gt;Prod1,Cust2,20&lt;BR /&gt;Prod1,Cust3,10&lt;BR /&gt;Prod2,Cust1,10&lt;BR /&gt;Prod2,Cust3,10&lt;BR /&gt;Prod3,Cust1,20&lt;BR /&gt;Prod3,Cust2,0&lt;BR /&gt;Prod4,Cust1,30&lt;BR /&gt;Prod5,Cust1,10&lt;BR /&gt;Prod5,Cust2,10&lt;BR /&gt;Prod5,Cust3,10&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;Then As you want to flag the products having the issue, You do not need a Pivot table. Having a straight table for Products with Product as Dimension and following Expression should give you the desired result:&lt;/P&gt;
&lt;P&gt;If(Count(Discount)=Count(Distinct Total Customer) and Count(Distinct Discount)=1,'OK','Issue')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I generally prefer doing this flag generating in the Script, to keep the expressions simple in the frontend. Using count Distinct is bad for performance if your dataset is large. So you could use the method suggested by &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/58578"&gt;@edwin&lt;/a&gt;&amp;nbsp; and add Alert generation as the last step for each product.&lt;/P&gt;</description>
    <pubDate>Sat, 06 Aug 2022 08:45:50 GMT</pubDate>
    <dc:creator>vidyutverma</dc:creator>
    <dc:date>2022-08-06T08:45:50Z</dc:date>
    <item>
      <title>Compare values within a customer group / pivot table columns</title>
      <link>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1964725#M79523</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I tried searching for a similar issue but could not find a solution.&lt;/P&gt;
&lt;P&gt;I need to compare customer discounts for a subset of accounts and if they are not the same or some are missing flag it as an issue.&lt;/P&gt;
&lt;P&gt;Ideally the output would be displayed in a pivot table with product code as the dimension and customer account number as the columns.&lt;/P&gt;
&lt;P&gt;Example data attached.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;A master customer has 5(number varies) different accounts across the group. Each account will have various discounts, some could have none at all. Once the master customer is selected, the output would compare the discounts across these 5 accounts for each product and if:&lt;/P&gt;
&lt;P&gt;1. They are not the same&lt;/P&gt;
&lt;P&gt;2. Some are missing&lt;/P&gt;
&lt;P&gt;Create a flag to filter them on and all the issues be visible in a pivot table.&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 15:46:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1964725#M79523</guid>
      <dc:creator>beijerltd</dc:creator>
      <dc:date>2022-08-04T15:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values within a customer group / pivot table columns</title>
      <link>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1965458#M79566</link>
      <description>&lt;P&gt;i would backfill missing entries with or a negative number that will surely not be in your discounts.&amp;nbsp; the reason i would do that is a missing data point will be null and it will be hard to capture.&lt;/P&gt;
&lt;P&gt;then i will just count the distinct number of discounts - if =1 then all discounts are the same and none are missing, else not all discounts are the same or at least one is missing:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;tmp1:&lt;BR /&gt;load Distinct&lt;BR /&gt;Master, Cus&lt;BR /&gt;Resident data;&lt;/P&gt;
&lt;P&gt;tmp2:&lt;BR /&gt;load Distinct&lt;BR /&gt;Master, Prod&lt;BR /&gt;Resident data;&lt;/P&gt;
&lt;P&gt;inner join (tmp1)&lt;BR /&gt;load *, 0 as [Discount%]&lt;BR /&gt;Resident tmp2;&lt;/P&gt;
&lt;P&gt;Concatenate (data)&lt;BR /&gt;load * Resident tmp1;&lt;/P&gt;
&lt;P&gt;drop table tmp1, tmp2;&lt;/P&gt;
&lt;P&gt;NoConcatenate&lt;BR /&gt;newData:&lt;BR /&gt;load Master,Cus,Prod,max([Discount%]) as [Discount%]&lt;BR /&gt;Resident data&lt;BR /&gt;group by Master,Cus,Prod;&lt;/P&gt;
&lt;P&gt;drop table data;&lt;/P&gt;
&lt;P&gt;this is the expression wil be:&lt;BR /&gt;&lt;BR /&gt;if(aggr(nodistinct Count(distinct [Discount%]),Prod)&amp;lt;&amp;gt;1,'ALERT', 'OK')&lt;/P&gt;
&lt;P&gt;this is the data for 1st master, except for prod1, i changed prod 1 and 2 so&amp;nbsp; there will at least be one row that will pass, and 1 row that will not have a missing discount but will have different discounts:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_1-1659736356333.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/86125i0BE301C527B72C75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_1-1659736356333.png" alt="edwin_1-1659736356333.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;this is how it looks like after backfilling it with 0 discounts:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_2-1659736417535.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/86126i91AC20CE5AE77AB5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_2-1659736417535.png" alt="edwin_2-1659736417535.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and this is your result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_3-1659736450483.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/86127iA95AA9F11BD0D938/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_3-1659736450483.png" alt="edwin_3-1659736450483.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;only 1 row has uniform discounts and the rest have either non-uniform or missing discounts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 21:54:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1965458#M79566</guid>
      <dc:creator>edwin</dc:creator>
      <dc:date>2022-08-05T21:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Compare values within a customer group / pivot table columns</title>
      <link>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1965475#M79569</link>
      <description>&lt;P&gt;Assuming that You have a table like this:&lt;/P&gt;
&lt;P&gt;Load * Inline [&lt;BR /&gt;Product, Customer, Discount&lt;BR /&gt;Prod1,Cust1,10&lt;BR /&gt;Prod1,Cust2,20&lt;BR /&gt;Prod1,Cust3,10&lt;BR /&gt;Prod2,Cust1,10&lt;BR /&gt;Prod2,Cust3,10&lt;BR /&gt;Prod3,Cust1,20&lt;BR /&gt;Prod3,Cust2,0&lt;BR /&gt;Prod4,Cust1,30&lt;BR /&gt;Prod5,Cust1,10&lt;BR /&gt;Prod5,Cust2,10&lt;BR /&gt;Prod5,Cust3,10&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;Then As you want to flag the products having the issue, You do not need a Pivot table. Having a straight table for Products with Product as Dimension and following Expression should give you the desired result:&lt;/P&gt;
&lt;P&gt;If(Count(Discount)=Count(Distinct Total Customer) and Count(Distinct Discount)=1,'OK','Issue')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I generally prefer doing this flag generating in the Script, to keep the expressions simple in the frontend. Using count Distinct is bad for performance if your dataset is large. So you could use the method suggested by &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/58578"&gt;@edwin&lt;/a&gt;&amp;nbsp; and add Alert generation as the last step for each product.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 08:45:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Compare-values-within-a-customer-group-pivot-table-columns/m-p/1965475#M79569</guid>
      <dc:creator>vidyutverma</dc:creator>
      <dc:date>2022-08-06T08:45:50Z</dc:date>
    </item>
  </channel>
</rss>

