<?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 Script: sum the values of a field in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346989#M128368</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe you need an additional load with an aggregation function SUM to get what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Though the Help says about the aggregation functions:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;These functions can only be used in field lists for &lt;A class="MCXref_0"&gt;Load&lt;/A&gt; statements with a &lt;SPAN class="Bold"&gt;group by&lt;/SPAN&gt; clause. &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that you actually don't need a group by clause:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;sum(PalletCount) as SumPallets&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;resident YOUREXISTINGRESIDENTTABLE;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Let TotalPallets = fieldvalue('SumPallets',1);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should result in a variable TotalPallets with your requested sum of PalletCount field values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 11 Mar 2012 16:31:40 GMT</pubDate>
    <dc:creator>swuehl</dc:creator>
    <dc:date>2012-03-11T16:31:40Z</dc:date>
    <item>
      <title>Script: sum the values of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346987#M128366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to sum the vlaues of a field in script? I need to use the total of all the foield values in the load statement fro a subsequent table. It would be nice if I could calulate the total of the field and assign this to a variable. I have tried the following, but it doesn't seem the work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET TotalPallets = SUM(PalletCount);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where PalletCount of a previously loaded field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Mar 2012 16:09:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346987#M128366</guid>
      <dc:creator />
      <dc:date>2012-03-11T16:09:16Z</dc:date>
    </item>
    <item>
      <title>Script: sum the values of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346988#M128367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use an aggregated load and then assign the value using function peek(). Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(PalletCount) as SumPalletCount&lt;/P&gt;&lt;P&gt;resident&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyTable&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vTotalPallets = peek('SumPalletCount');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oleg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Mar 2012 16:27:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346988#M128367</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2012-03-11T16:27:14Z</dc:date>
    </item>
    <item>
      <title>Script: sum the values of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346989#M128368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe you need an additional load with an aggregation function SUM to get what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Though the Help says about the aggregation functions:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;These functions can only be used in field lists for &lt;A class="MCXref_0"&gt;Load&lt;/A&gt; statements with a &lt;SPAN class="Bold"&gt;group by&lt;/SPAN&gt; clause. &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that you actually don't need a group by clause:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;sum(PalletCount) as SumPallets&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;resident YOUREXISTINGRESIDENTTABLE;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Let TotalPallets = fieldvalue('SumPallets',1);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should result in a variable TotalPallets with your requested sum of PalletCount field values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Mar 2012 16:31:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-sum-the-values-of-a-field/m-p/346989#M128368</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-03-11T16:31:40Z</dc:date>
    </item>
  </channel>
</rss>

