<?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 Margin calculation with missing values in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239393#M90024</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post the sample QV file&lt;/P&gt;&lt;P&gt;Nimish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 31 Jul 2010 16:25:22 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-07-31T16:25:22Z</dc:date>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239392#M90023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm looking for a way for calculating a global gross margin when some cost values are missing. I mean, I'm using this expression for margin calculation:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;sum(Price-Cost) / sum(Price)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The problem is, I have some item where Cost is missing. Therefore, I would like to discard these rows in the calculation in order to have a realistic total margin (in other words: global margin of the items with a cost). Of course, I could simply filter off the rows with missing cost from my table, but I would like to avoid that.&lt;BR /&gt;I tried with&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if(Cost&amp;gt;0, sum(Price-Cost) / sum(Price) )&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This is OK row by row, but the total row ends up as a null value. Then I tried&lt;/P&gt;&lt;P&gt;&lt;EM&gt;sum({$&amp;lt;Cost={'&amp;gt;0'}&amp;gt;} Price-Cost) / sum({$&amp;lt;Cost={'&amp;gt;0'}&amp;gt;} Price)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This is correct row by row as well, but the total value has nothing to do with the "correct" one.&lt;BR /&gt;Any suggestion?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Jul 2010 10:17:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239392#M90023</guid>
      <dc:creator />
      <dc:date>2010-07-31T10:17:22Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239393#M90024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post the sample QV file&lt;/P&gt;&lt;P&gt;Nimish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Jul 2010 16:25:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239393#M90024</guid>
      <dc:creator />
      <dc:date>2010-07-31T16:25:22Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239394#M90025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe you can try&lt;/P&gt;&lt;P&gt;Sum(if(Cost&amp;gt;0,Price-Cost,0))/Sum(if(Cost&amp;gt;0,Price,0))&lt;/P&gt;&lt;P&gt;Nimish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Jul 2010 18:13:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239394#M90025</guid>
      <dc:creator />
      <dc:date>2010-07-31T18:13:55Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239395#M90026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You Numish&lt;/P&gt;&lt;P&gt;here it is a sample. Sorry for the italian names of the fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Jul 2010 22:52:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239395#M90026</guid>
      <dc:creator />
      <dc:date>2010-07-31T22:52:10Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239396#M90027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry Paolo but cannot understand the sample you have uploaded. The dimensions which are shown are different than the ones used in the expression so am having a difficult time to understand what you are tyring to do. Can you put it in excel and tell what is it that you are expecting&lt;/P&gt;&lt;P&gt;Nimish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Aug 2010 01:19:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239396#M90027</guid>
      <dc:creator />
      <dc:date>2010-08-02T01:19:26Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239397#M90028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I had to simplify an huge document in order to be attached and some dimensions were obtained in different way.&lt;BR /&gt;Basically, as you can see in the xls file, I would like my total margin to be (Total sales-Total cost)/(Total sales), but I get different values. I know there's something I'm missing, there should be a way....&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Aug 2010 08:27:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239397#M90028</guid>
      <dc:creator />
      <dc:date>2010-08-02T08:27:02Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239398#M90029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Paolo,&lt;/P&gt;&lt;P&gt;Went through your excel file. What I noticed is that for the global marin (my margin column), your total Sales column includes the sale price of the item which has zero cost. As a result, you are getting the margin of 37.66. If you remove this sale value (103.26) from the total, you will get a margin of 36.98. This is exactly what you will get in QV using the set analysis which you have mentioned in your post.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;sum({$&amp;lt;Cost={'&amp;gt;0'}&amp;gt;} Price-Cost) / sum({$&amp;lt;Cost={'&amp;gt;0'}&amp;gt;} Price)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;For convinience, I have taken your sample excel data in qv and recreated the situation.&lt;/P&gt;&lt;P&gt;Do let me know if I have understood you problem correctly.&lt;/P&gt;&lt;P&gt;Nimish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Aug 2010 15:49:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239398#M90029</guid>
      <dc:creator />
      <dc:date>2010-08-02T15:49:05Z</dc:date>
    </item>
    <item>
      <title>Margin calculation with missing values</title>
      <link>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239399#M90030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You got it!&lt;/P&gt;&lt;P&gt;What I was missing is simply the quotes in the "&amp;gt;0" string. Too bad...&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Paolo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 16:50:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Margin-calculation-with-missing-values/m-p/239399#M90030</guid>
      <dc:creator />
      <dc:date>2010-08-03T16:50:56Z</dc:date>
    </item>
  </channel>
</rss>

