<?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 Complicated calculation in a chart in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325790#M119961</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Swuehl,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, your idea led me to the solution.&lt;/P&gt;&lt;P&gt;Indeed defining the problem is the hardest part for the suolution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=sum(aggr(Sum( {&amp;lt;PricingModel={'dCPC'}&amp;gt;} cost)*Margin,Campaign_ID))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realised that in there are 2 steps needed for this calculation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Sum(Cost) AS &lt;STRONG&gt;SUM&lt;/STRONG&gt;, CampaignId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (only for PricingModel = 'dCPC')&lt;/P&gt;&lt;P&gt;3. Sum(&lt;STRONG&gt;SUM&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Explanation: &lt;/P&gt;&lt;P&gt;becuase i need to multiply the Sum(Cost) by Margin (only for PricingModel = 'dCPC'), and because i know that a Margin is defined by the Campain, I need to first to "prepare" a data set that is grouped by CampignID (see the AGGR part of the expression above).&lt;BR /&gt;So, first i prepare a set that Sum the cost per Campaign (and therefore the Sum can be multiply by the Margin, which depends on the Campign).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, i need to Sum these results to get the revenue for all the campaigns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And that Works,&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Feb 2012 09:39:23 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-02-29T09:39:23Z</dc:date>
    <item>
      <title>Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325785#M119956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I try to calculate a revenue in a chart, but the logic makes it hard to implement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;= Sum( {&amp;lt;Traff_Campaigns.PricingModel={'dCPC'}&amp;gt;} cost)*&lt;SPAN style="color: #ff0000;"&gt;Traff_Campaigns.Margin&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;The idea is, for example, if it is about PricingModel &lt;SPAN style="color: #000000;"&gt;"dCPC"&lt;/SPAN&gt;, we need to sum the "cost" and then multiply it by &lt;SPAN style="color: #ff0000;"&gt;Margin. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;But&amp;nbsp; when i use this calculation, it not works well for all dimension in the chart (see attatched .qvw) .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;I guess the expression does not know how to deal with the multiply of the Margin, since it could be many margins for the same PricingModel.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 17:07:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325785#M119956</guid>
      <dc:creator />
      <dc:date>2012-02-28T17:07:43Z</dc:date>
    </item>
    <item>
      <title>Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325786#M119957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if there are multiple margins, what do you want to do? Choose one? Multiply by an average of them all? Add them together before multiplying?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 17:16:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325786#M119957</guid>
      <dc:creator>Jason_Michaelides</dc:creator>
      <dc:date>2012-02-28T17:16:17Z</dc:date>
    </item>
    <item>
      <title>Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325787#M119958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Guy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are right, that's almost for sure one issue. Another one might be that it seems that you don't have Margins set for every cost line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume you could probably get a better result if you are using an advanced aggregation using an appropriate dimension (on finest level of details), since you are also using a group dimension, maybe like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=sum(aggr( Sum( {&amp;lt;Traff_Campaigns.PricingModel={'dCPC'}&amp;gt;} cost)*Traff_Campaigns.Margin,Traff_Plat_Key))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as expression in your chart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still some lines get zero revenue, because there seems to be no&amp;nbsp; Margin value linked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 17:22:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325787#M119958</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-02-28T17:22:14Z</dc:date>
    </item>
    <item>
      <title>Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325788#M119959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are the result correct if you change the expression to:&lt;/P&gt;&lt;P&gt;= Sum( {&amp;lt;Traff_Campaigns.PricingModel={'dCPC'}&amp;gt;} DISTINCT cost*Traff_Campaigns.Margin)&lt;/P&gt;&lt;P&gt;?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 17:22:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325788#M119959</guid>
      <dc:creator />
      <dc:date>2012-02-28T17:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325789#M119960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And your margins are probably given in Percent, so you need to divide by 100.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 17:39:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325789#M119960</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-02-28T17:39:24Z</dc:date>
    </item>
    <item>
      <title>Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325790#M119961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Swuehl,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, your idea led me to the solution.&lt;/P&gt;&lt;P&gt;Indeed defining the problem is the hardest part for the suolution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=sum(aggr(Sum( {&amp;lt;PricingModel={'dCPC'}&amp;gt;} cost)*Margin,Campaign_ID))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realised that in there are 2 steps needed for this calculation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Sum(Cost) AS &lt;STRONG&gt;SUM&lt;/STRONG&gt;, CampaignId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (only for PricingModel = 'dCPC')&lt;/P&gt;&lt;P&gt;3. Sum(&lt;STRONG&gt;SUM&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Explanation: &lt;/P&gt;&lt;P&gt;becuase i need to multiply the Sum(Cost) by Margin (only for PricingModel = 'dCPC'), and because i know that a Margin is defined by the Campain, I need to first to "prepare" a data set that is grouped by CampignID (see the AGGR part of the expression above).&lt;BR /&gt;So, first i prepare a set that Sum the cost per Campaign (and therefore the Sum can be multiply by the Margin, which depends on the Campign).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, i need to Sum these results to get the revenue for all the campaigns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And that Works,&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 09:39:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325790#M119961</guid>
      <dc:creator />
      <dc:date>2012-02-29T09:39:23Z</dc:date>
    </item>
    <item>
      <title>Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325791#M119962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Out of interest, Guy, what do you do when there is no margin linked to the campaign as I think the result will be null?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 09:44:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325791#M119962</guid>
      <dc:creator>Jason_Michaelides</dc:creator>
      <dc:date>2012-02-29T09:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325792#M119963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jason,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expression:&amp;nbsp;&amp;nbsp;&amp;nbsp; =Sum(AGGR(Sum( {&amp;lt;PricingModel={'dCPC'}&amp;gt;} cost)&lt;STRONG&gt;*Margin&lt;/STRONG&gt;,Campaign_ID))&lt;/P&gt;&lt;P&gt;inheretely deals with &lt;STRONG&gt;Margin &lt;/STRONG&gt;that is Null, because the AGGR returns 0 this way, and therefore when a campaign has no Margin defined, the calulation for him will be 0, and not Null.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attached the fixed QVW.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a good day!&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 12:31:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325792#M119963</guid>
      <dc:creator />
      <dc:date>2012-02-29T12:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated calculation in a chart</title>
      <link>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325793#M119964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got it.&amp;nbsp; Cheers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 12:42:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Complicated-calculation-in-a-chart/m-p/325793#M119964</guid>
      <dc:creator>Jason_Michaelides</dc:creator>
      <dc:date>2012-02-29T12:42:17Z</dc:date>
    </item>
  </channel>
</rss>

