<?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: Expression in table/pivot table to show totals over same field in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1651464#M48588</link>
    <description>&lt;P&gt;Sorry for the late answer, I had to find time for testing. Your solution was correct: the problem was in the model. Using a different model solved the problem.&lt;/P&gt;&lt;P&gt;I modified your solution to better suit my idea, creating a concatenated table:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//Read raw data
[Tmp_Sales]:
LOAD
[Document_ID],
[CustomerID],
[Sales_Value],
[Linked_CustomerID]
FROM [lib://Desktop/QlikCommunityExample.xlsx]
(ooxml, embedded labels, table is Sheet1);



//Direct sales table
[Sales]:
LOAD 
[Document_ID]&amp;amp;'|'&amp;amp;[CustomerID] as [_Key_Sales],
[CustomerID],
[CustomerID] as [FinalCustomerID],
[Document_ID],
[Sales_Value],
'Direct' as [Sales Type]
Resident [Tmp_Sales];

Concatenate

//Linked sales
[Linked_Sales]:
Load
[Document_ID]&amp;amp;'|'&amp;amp;[Linked_CustomerID] as [_Key_Sales],
[Linked_CustomerID] as [CustomerID],
[CustomerID] as [FinalCustomerID],
[Document_ID],
[Sales_Value] as [Linked_Sales_Value],
'Linked' as [Sales Type]
Resident [Tmp_Sales]
Where IsNull([Linked_CustomerID])=False(); //this condition includes only linked sales, identified by the presence of a linked_CustomerID; if null, then it's a direct sale 



//Drop raw data
drop table [Tmp_Sales];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final solution is attached to this post. Thanks a lot for your help and your time, Jerifortune. Best wishes.&lt;/P&gt;&lt;P&gt;- FR&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 14:48:21 GMT</pubDate>
    <dc:creator>Federico_Rizzello</dc:creator>
    <dc:date>2019-11-26T14:48:21Z</dc:date>
    <item>
      <title>Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1632504#M47103</link>
      <description>&lt;P&gt;Hi to all,&lt;/P&gt;&lt;P&gt;I have a data model with this table:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;SALES&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DocumentID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Linked_CustomerID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CustomerID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sales_Value&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The field "Linked_CustomerID" is a referral to a "CustomerID": each document has a "CustomerID" (final buyer), but sometimes these customers buy using a referral link given to them by another customer (inviting customer), stored in the field "Linked_CustomerID".&lt;/P&gt;&lt;P&gt;My objective is creating a straight/pivot table with this structure:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Label&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;CustomerID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Customer Sales&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Customer Linked Sales&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Comment&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;The final buyer&lt;/TD&gt;&lt;TD&gt;Total direct sales of the customer&amp;nbsp;(sum(Sales_Value))&lt;/TD&gt;&lt;TD&gt;Total sales of all the other customers who used the referral link of the customer "CustomerID"&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Expected result&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;ACME SRL&lt;/TD&gt;&lt;TD&gt;1.000 €&lt;/TD&gt;&lt;TD&gt;250 €&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is: what is the correct expression and set analysis for the column "Customer Linked Sales" in order to achieve the above table?&lt;/P&gt;&lt;P&gt;I tried different expressions, using aggr() and p() but without success. The thing is that my users should get a table by "CustomerID" with 1) the total direct sales of that specific customer and 2) the total sales of all the other customers invited by him. Is this even possibile?&lt;/P&gt;&lt;P&gt;Thanks in advance for any advice. Best regards.&lt;/P&gt;&lt;P&gt;- Federico Rizzello&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 04:26:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1632504#M47103</guid>
      <dc:creator>Federico_Rizzello</dc:creator>
      <dc:date>2024-11-16T04:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1632669#M47117</link>
      <description>&lt;P&gt;No sure if I get you right.&lt;BR /&gt;&lt;BR /&gt;You want to get the total of 1250 against customer&amp;nbsp;&lt;SPAN&gt;ACME SRL?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 17:32:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1632669#M47117</guid>
      <dc:creator>jerifortune</dc:creator>
      <dc:date>2019-10-08T17:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1633476#M47163</link>
      <description>&lt;P&gt;Hi Jerifortune, thanks for your interest.&lt;/P&gt;&lt;P&gt;No, I don't need to calculate the total of 1.250 €, I'm in search of the formula to calculate the column "Customer Linked Sales" of 250 € against each customer. The idea behind it is:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;calculate the sum of Sales of &lt;U&gt;other &lt;/U&gt;customers who purchased using the referral link of the customer ACME&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 07:47:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1633476#M47163</guid>
      <dc:creator>Federico_Rizzello</dc:creator>
      <dc:date>2019-10-10T07:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1633677#M47188</link>
      <description>&lt;P&gt;Do you have a sample data? I think it is more on the modeling side than expression.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 13:28:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1633677#M47188</guid>
      <dc:creator>jerifortune</dc:creator>
      <dc:date>2019-10-10T13:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1641864#M47834</link>
      <description>&lt;P&gt;Sorry for the late reply, and thanks for your interest.&lt;/P&gt;&lt;P&gt;I attached some raw data and an app with sample data and some comments about my problem. Thanks for any advice!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 18:48:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1641864#M47834</guid>
      <dc:creator>Federico_Rizzello</dc:creator>
      <dc:date>2019-10-31T18:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1646004#M48157</link>
      <description>&lt;P&gt;Hi Federico,&lt;BR /&gt;&lt;BR /&gt;Sorry, I was busy with other projects and didn't come here since your last response.&lt;/P&gt;&lt;P&gt;I adjusted your model as :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Set dataManagerTables = '','Sheet1';&lt;BR /&gt;//This block renames script tables from non generated section which conflict with the names of managed tables&lt;/P&gt;&lt;P&gt;For each name in $(dataManagerTables)&lt;BR /&gt;Let index = 0;&lt;BR /&gt;Let currentName = name;&lt;BR /&gt;Let tableNumber = TableNumber(name);&lt;BR /&gt;Let matches = 0;&lt;BR /&gt;Do while not IsNull(tableNumber) or (index &amp;gt; 0 and matches &amp;gt; 0)&lt;BR /&gt;index = index + 1;&lt;BR /&gt;currentName = name &amp;amp; '-' &amp;amp; index;&lt;BR /&gt;tableNumber = TableNumber(currentName)&lt;BR /&gt;matches = Match('$(currentName)', $(dataManagerTables));&lt;BR /&gt;Loop&lt;BR /&gt;If index &amp;gt; 0 then&lt;BR /&gt;Rename Table '$(name)' to '$(currentName)';&lt;BR /&gt;EndIf;&lt;BR /&gt;Next;&lt;BR /&gt;Set dataManagerTables = ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Unqualify *;&lt;/P&gt;&lt;P&gt;[Sheet1]:&lt;BR /&gt;LOAD&lt;BR /&gt;[Document_ID],&lt;BR /&gt;[CustomerID],&lt;BR /&gt;[Sales_Value],&lt;BR /&gt;[Linked_CustomerID]&lt;BR /&gt;FROM [lib://Desktop/QlikCommunityExample.xlsx]&lt;BR /&gt;(ooxml, embedded labels, table is Sheet1);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;CustomerSales:&lt;BR /&gt;LOAD //[Document_ID],&lt;BR /&gt;[CustomerID],&lt;BR /&gt;[Sales_Value]&lt;BR /&gt;&lt;BR /&gt;Resident [Sheet1]&lt;BR /&gt;WHERE LEN([Linked_CustomerID]) &amp;lt; 1&lt;BR /&gt;;&lt;BR /&gt;NoConcatenate&lt;BR /&gt;LinkedCustomerSales:&lt;BR /&gt;LOAD&lt;BR /&gt;// [Document_ID],&lt;BR /&gt;[Linked_CustomerID] AS [CustomerID],&lt;BR /&gt;[Sales_Value] AS LinkedCustomerSales,&lt;BR /&gt;[Linked_CustomerID]&lt;BR /&gt;Resident [Sheet1]&lt;BR /&gt;WHERE LEN([Linked_CustomerID]) &amp;gt; 0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 16:39:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1646004#M48157</guid>
      <dc:creator>jerifortune</dc:creator>
      <dc:date>2019-11-12T16:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Expression in table/pivot table to show totals over same field</title>
      <link>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1651464#M48588</link>
      <description>&lt;P&gt;Sorry for the late answer, I had to find time for testing. Your solution was correct: the problem was in the model. Using a different model solved the problem.&lt;/P&gt;&lt;P&gt;I modified your solution to better suit my idea, creating a concatenated table:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//Read raw data
[Tmp_Sales]:
LOAD
[Document_ID],
[CustomerID],
[Sales_Value],
[Linked_CustomerID]
FROM [lib://Desktop/QlikCommunityExample.xlsx]
(ooxml, embedded labels, table is Sheet1);



//Direct sales table
[Sales]:
LOAD 
[Document_ID]&amp;amp;'|'&amp;amp;[CustomerID] as [_Key_Sales],
[CustomerID],
[CustomerID] as [FinalCustomerID],
[Document_ID],
[Sales_Value],
'Direct' as [Sales Type]
Resident [Tmp_Sales];

Concatenate

//Linked sales
[Linked_Sales]:
Load
[Document_ID]&amp;amp;'|'&amp;amp;[Linked_CustomerID] as [_Key_Sales],
[Linked_CustomerID] as [CustomerID],
[CustomerID] as [FinalCustomerID],
[Document_ID],
[Sales_Value] as [Linked_Sales_Value],
'Linked' as [Sales Type]
Resident [Tmp_Sales]
Where IsNull([Linked_CustomerID])=False(); //this condition includes only linked sales, identified by the presence of a linked_CustomerID; if null, then it's a direct sale 



//Drop raw data
drop table [Tmp_Sales];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final solution is attached to this post. Thanks a lot for your help and your time, Jerifortune. Best wishes.&lt;/P&gt;&lt;P&gt;- FR&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 14:48:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expression-in-table-pivot-table-to-show-totals-over-same-field/m-p/1651464#M48588</guid>
      <dc:creator>Federico_Rizzello</dc:creator>
      <dc:date>2019-11-26T14:48:21Z</dc:date>
    </item>
  </channel>
</rss>

