<?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: Average based on another dimension in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388403#M1167724</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;The expression:&lt;/P&gt;&lt;P&gt;=Avg(aggr(Sum(profit) / Sum(cost), Invoice, Customer)&lt;/P&gt;&lt;P&gt;is also right. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems some Invoices has equal names for different customers in your case&lt;/P&gt;&lt;P&gt;(so with my expression it appears only for one customer - my fault).&lt;/P&gt;&lt;P&gt;The above expression resolves this issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 07 Oct 2012 08:14:49 GMT</pubDate>
    <dc:creator>whiteline</dc:creator>
    <dc:date>2012-10-07T08:14:49Z</dc:date>
    <item>
      <title>Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388396#M1167712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a Straight Table for which I'm trying to add a calculated field that is based on another dimension, one which is not part of the straight table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Essentially, the dimension on the table is customer name. I want to add a column which shows, for each customer, the average profit margin per sale, where profit margin per sale is the total profit / total cost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To illustrate, below is the data for a single customer:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Invoice&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Product&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Cost&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Profit&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Invoice A&lt;/TD&gt;&lt;TD&gt;Item A&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;TD&gt;$15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Invoice A&lt;/TD&gt;&lt;TD&gt;Item B&lt;/TD&gt;&lt;TD&gt;$20&lt;/TD&gt;&lt;TD&gt;$40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Invoice B&lt;/TD&gt;&lt;TD&gt;Item C&lt;/TD&gt;&lt;TD&gt;$15&lt;/TD&gt;&lt;TD&gt;$15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Invoice B&lt;/TD&gt;&lt;TD&gt;Item D&lt;/TD&gt;&lt;TD&gt;$20&lt;/TD&gt;&lt;TD&gt;$40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Invoice C&lt;/TD&gt;&lt;TD&gt;Item E&lt;/TD&gt;&lt;TD&gt;$5&lt;/TD&gt;&lt;TD&gt;$25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Invoice D&lt;/TD&gt;&lt;TD&gt;Item F&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;TD&gt;$10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we calculate over the dimension of invoice, I get that Invoice A had a profit margin of 1.83 (55/30), Invoice B was 1.57 (55/35), Invoice C was 5.0 (25/5) and Invoice D was 1.0 (10/10).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The average of these margins, for this customer, is 2.35, which is the number I'm trying to get in my other table. If we just add the costs and the profits, and calculate the margin, we come up with 1.81.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The equation I tried writing was as follows (on a straight table with dimension customer), but it doesn't quite work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Avg(total&amp;lt;Invoice&amp;gt; aggr(sum(profit) / sum(cost), Customer))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Note, I currently only have access to Personal Edition, and so cannot open other Qlikview files)&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2012 21:12:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388396#M1167712</guid>
      <dc:creator />
      <dc:date>2012-10-05T21:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388397#M1167714</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;Having a Customer as dimension your expresison is already calculated for each customer.&lt;/P&gt;&lt;P&gt;Then you want to calculate the &lt;SPAN style="text-decoration: underline;"&gt;average of margins &lt;STRONG&gt;of invoices&lt;/STRONG&gt;&lt;/SPAN&gt; for the customer:&lt;/P&gt;&lt;P&gt;=Avg(aggr(sum(profit) / sum(cost), &lt;STRONG&gt;Invoice&lt;/STRONG&gt;)) &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2012 09:20:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388397#M1167714</guid>
      <dc:creator>whiteline</dc:creator>
      <dc:date>2012-10-06T09:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388398#M1167716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like even the avg isn't necessary. This seems to work too:&lt;/P&gt;&lt;P&gt;=aggr(sum(Profit) / sum(Cost), Invoice) &lt;/P&gt;&lt;P&gt;=aggr(sum(Profit) / sum(Cost), Customer) &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2012 09:29:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388398#M1167716</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2012-10-06T09:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388399#M1167718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, gwassenaar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;=aggr(sum(Profit) / sum(Cost), Invoice)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This gives a list of values of average margins &lt;SPAN style="text-decoration: underline;"&gt;for each Invoice&lt;/SPAN&gt;, and if is used&amp;nbsp; with Customer as dimension, you need avg() to aggregate. If is used with Invoice as dimension it 'works' but the aggr() is useless.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;=aggr(sum(Profit) / sum(Cost), Customer)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This gives a list of values of &lt;SPAN style="text-decoration: underline;"&gt;weighted&lt;/SPAN&gt; average margins &lt;SPAN style="text-decoration: underline;"&gt;for each Customer&lt;/SPAN&gt;,&amp;nbsp; whereas Elie asked about &lt;SPAN style="text-decoration: underline;"&gt;simple&lt;/SPAN&gt; average of margins &lt;SPAN style="text-decoration: underline;"&gt;of invoices&lt;/SPAN&gt; for each customer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2012 10:32:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388399#M1167718</guid>
      <dc:creator>whiteline</dc:creator>
      <dc:date>2012-10-06T10:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388400#M1167720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In my example I get the same values from all three variants. Obviously I don't get it. Can you explain what I'm doing wrong? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2012 10:49:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388400#M1167720</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2012-10-06T10:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388401#M1167722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;gwassenaar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the task as defined by Elie is to calculate the numbers in the context of the only chart dimension Customer, where you are using additional dimensions Invoice and Product, right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remove these two dimensions, and you will see the difference.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2012 12:09:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388401#M1167722</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-10-06T12:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388402#M1167723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, just tried this now, and definitely have made progress, but it still doesn't seem correct - at least, the numbers appear to be off.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the following equations, with questionable results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Avg(aggr(Sum(profit) / Sum(cost), Invoice)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a few results saying 0 and a bunch of rows indicating that it's not calculatable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the following, and it seems to work much better, but I'm not sure why:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Avg(aggr(Sum(profit) / Sum(cost), Invoice, Customer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The results appear to be much more realistic, and it seems that I'm getting normal results for all customers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 01:25:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388402#M1167723</guid>
      <dc:creator />
      <dc:date>2012-10-07T01:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Average based on another dimension</title>
      <link>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388403#M1167724</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;The expression:&lt;/P&gt;&lt;P&gt;=Avg(aggr(Sum(profit) / Sum(cost), Invoice, Customer)&lt;/P&gt;&lt;P&gt;is also right. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems some Invoices has equal names for different customers in your case&lt;/P&gt;&lt;P&gt;(so with my expression it appears only for one customer - my fault).&lt;/P&gt;&lt;P&gt;The above expression resolves this issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 08:14:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Average-based-on-another-dimension/m-p/388403#M1167724</guid>
      <dc:creator>whiteline</dc:creator>
      <dc:date>2012-10-07T08:14:49Z</dc:date>
    </item>
  </channel>
</rss>

