<?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 to get correct sum value in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977759#M334015</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SUM(DISTINCT Cost)&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;SUM(Cost)/Count(Comany)&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;AVG(Aggr(SUM(Cost),Comany,ChangeID))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Oct 2015 14:43:23 GMT</pubDate>
    <dc:creator>MK_QSL</dc:creator>
    <dc:date>2015-10-01T14:43:23Z</dc:date>
    <item>
      <title>Expression to get correct sum value</title>
      <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977755#M334011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to get the sum of costs for a user based on the ID and the company.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my example script which return the wrong sum as you can see in the screenshot. &lt;/P&gt;&lt;P&gt;So the correct output would be 2 for User A in company X and 4 for user B in company Y&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is the ChangeID which creates additional rows for each ID.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, User, ChangeID, Cost, Comany&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1, A, 1, 2, X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1, A, 2, 2, X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1, A, 3, 2, X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, B, 1, 4, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, B, 2, 4, Y&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;IMG alt="a.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/100653_a.PNG" style="height: 152px; width: 620px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you show me how this can be done?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Oct 2015 14:14:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977755#M334011</guid>
      <dc:creator />
      <dc:date>2015-10-01T14:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Expression to get correct sum value</title>
      <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977756#M334012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sum(Aggr(Sum(distinct Cost), User))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Oct 2015 14:18:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977756#M334012</guid>
      <dc:creator>pamaxeed</dc:creator>
      <dc:date>2015-10-01T14:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Expression to get correct sum value</title>
      <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977757#M334013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thorsten, one easy solution is using Avg() instead of Sum(), can this work on your complete model?.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For working also in totals you can use:&lt;/P&gt;&lt;P&gt;Sum(Aggr(Avg(Cost), User))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Oct 2015 14:19:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977757#M334013</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-10-01T14:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Expression to get correct sum value</title>
      <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977758#M334014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use User as dimension and&lt;/P&gt;&lt;P&gt;Aggr(FirstSortedValue(Cost,-ChangeID),User) as expression&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Oct 2015 14:26:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977758#M334014</guid>
      <dc:creator>nagaiank</dc:creator>
      <dc:date>2015-10-01T14:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Expression to get correct sum value</title>
      <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977759#M334015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SUM(DISTINCT Cost)&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;SUM(Cost)/Count(Comany)&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;AVG(Aggr(SUM(Cost),Comany,ChangeID))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Oct 2015 14:43:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977759#M334015</guid>
      <dc:creator>MK_QSL</dc:creator>
      <dc:date>2015-10-01T14:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Expression to get correct sum value</title>
      <link>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977760#M334016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;thank you for your answers I had to make a slight modification to get it to work for me.&lt;/P&gt;&lt;P&gt;I also added a few more lines to the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the screenshot you can see that in the table box the sum of User A is &lt;STRONG&gt;8 &lt;/STRONG&gt;over all companies.&lt;/P&gt;&lt;P&gt;Sum(Aggr(Sum(distinct Cost), &lt;STRONG&gt;ID&lt;/STRONG&gt;)) did the trick for me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="a.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/100726_a.PNG" style="height: 155px; width: 620px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, User, ChangeID, Cost, Comany&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1, A, 1, 2, X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1, A, 2, 2, X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1, A, 3, 2, X&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, B, 1, 4, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2, B, 2, 4, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, A, 8, 2, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, A, 9, 2, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, A, 10, 2, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3, A, 11, 2, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4, A, 55, 4, Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4, A, 56, 4, Y&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Thorsten&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2015 05:52:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Expression-to-get-correct-sum-value/m-p/977760#M334016</guid>
      <dc:creator />
      <dc:date>2015-10-02T05:52:21Z</dc:date>
    </item>
  </channel>
</rss>

