<?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 average in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/average/m-p/154984#M31400</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not why it wouldn't load. Maybe it has a problem with the avg(). My first step would be to simplify the math and get rid of that part at the same time.&lt;/P&gt;&lt;P&gt;((sum(Price*Quantity)/sum(Quantity))-avg(Cost))/(sum(Price*Quantity)/sum(Quantity))&lt;BR /&gt;= ((sum(Price*Quantity)/sum(Quantity))-(sum(Cost*Quantity)/sum(Quantity))/(sum(Price*Quantity)/sum(Quantity))&lt;BR /&gt;= (sum(Price*Quantity)-sum(Cost*Quantity))/sum(Price*Quantity)&lt;BR /&gt;= &lt;STRONG&gt;1 - sum(Cost*Quantity)/sum(Price*Quantity)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;My next step would be to not precalculate the margin in the script. The margin depends on dividing sums, and therefore can't just be calculated for every row. You can calculate for groupings of fields in the script, which is what you seem to be trying to do, but there is no need. It is MUCH more flexible to just do the calculations in chart expressions, so that you can add and remove dimensions (including generating subtotals) without needing to reload your data and store an additional table.&lt;/P&gt;&lt;P&gt;See attached.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Aug 2009 01:09:57 GMT</pubDate>
    <dc:creator>johnw</dc:creator>
    <dc:date>2009-08-13T01:09:57Z</dc:date>
    <item>
      <title>average</title>
      <link>https://community.qlik.com/t5/QlikView/average/m-p/154983#M31399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Hi,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;I have a transaction table with this fields:&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="font-style: italic; margin: 0cm 0cm 0pt; mso-bidi-font-style: normal"&gt;Transaction:&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Year,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Month,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;ProductCode,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Price,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Cost,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Quantity,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;I need to calculate The Average (considering de quantity of de sell)&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;F.E. : if I have two transactions with diferent prices :&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Productcode price cost quantity Amount&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;A 130,79 105,64 16 2092,64&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;A 127,26 105,64 2 254,52&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;The average i need to calculate is this:&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;(Total Amount: 2347,16 / Total Quantity: 18 = ) &lt;B style="mso-bidi-font-weight: normal;"&gt;(130,39 -105,64) /130,39 = 0,18987&lt;/B&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;I`ve tried to calculate this in the following script but qlikview doesn`t finish the loading:&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Load:&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Year,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Month,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;ProductCode,&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt; text-indent: 35.4pt;"&gt;((Sum( Price*Quantity)/sum(quantity)) -avg(Cost)) /&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;(Sum( Price*Quantity)/sum(quantity)) as Average&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;resident Transaction&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;group by Year,Month, ProductCode;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Can anyone help me?&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Aug 2009 03:46:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/average/m-p/154983#M31399</guid>
      <dc:creator />
      <dc:date>2009-08-12T03:46:32Z</dc:date>
    </item>
    <item>
      <title>average</title>
      <link>https://community.qlik.com/t5/QlikView/average/m-p/154984#M31400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not why it wouldn't load. Maybe it has a problem with the avg(). My first step would be to simplify the math and get rid of that part at the same time.&lt;/P&gt;&lt;P&gt;((sum(Price*Quantity)/sum(Quantity))-avg(Cost))/(sum(Price*Quantity)/sum(Quantity))&lt;BR /&gt;= ((sum(Price*Quantity)/sum(Quantity))-(sum(Cost*Quantity)/sum(Quantity))/(sum(Price*Quantity)/sum(Quantity))&lt;BR /&gt;= (sum(Price*Quantity)-sum(Cost*Quantity))/sum(Price*Quantity)&lt;BR /&gt;= &lt;STRONG&gt;1 - sum(Cost*Quantity)/sum(Price*Quantity)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;My next step would be to not precalculate the margin in the script. The margin depends on dividing sums, and therefore can't just be calculated for every row. You can calculate for groupings of fields in the script, which is what you seem to be trying to do, but there is no need. It is MUCH more flexible to just do the calculations in chart expressions, so that you can add and remove dimensions (including generating subtotals) without needing to reload your data and store an additional table.&lt;/P&gt;&lt;P&gt;See attached.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2009 01:09:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/average/m-p/154984#M31400</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2009-08-13T01:09:57Z</dc:date>
    </item>
  </channel>
</rss>

