<?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 Calculating percentage based on conditions in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476172#M100246</link>
    <description>&lt;P&gt;Good day!&lt;/P&gt;
&lt;P&gt;Given this load script:&lt;/P&gt;
&lt;P&gt;Table:&lt;/P&gt;
&lt;P&gt;LOAD * Inline [&lt;/P&gt;
&lt;P&gt;ID,Item,Total,Pending&lt;/P&gt;
&lt;P&gt;A,A-1,10,8&lt;BR /&gt;A,A-2,12,7&lt;BR /&gt;B,B-1,190,124&lt;BR /&gt;C,C-1,18,2&lt;BR /&gt;C,C-2,100,60&lt;BR /&gt;D,D-1,2,2&lt;BR /&gt;D,D-2,10,8&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;I would like to get the Pending Rate (Sum of Pending/Sum of Total) for the IDs where the Sum of Total is &amp;gt;= 20. However, the value I am getting is as if I am not applying the condition that the Sum of Total is &amp;gt;= 20.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="adrianfer_0-1723597306555.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/170610i9E201CDD958AA0B0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="adrianfer_0-1723597306555.png" alt="adrianfer_0-1723597306555.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expression for Pending Rate for the second chart is :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If(Sum(Aggr(Sum(Total),ID))&amp;gt;=20, Sum(Pending)/Sum(Total))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached a sample file here.&lt;/P&gt;
&lt;P&gt;Appreciate all the help! Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Aug 2024 01:03:46 GMT</pubDate>
    <dc:creator>adrianfer</dc:creator>
    <dc:date>2024-08-14T01:03:46Z</dc:date>
    <item>
      <title>Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476172#M100246</link>
      <description>&lt;P&gt;Good day!&lt;/P&gt;
&lt;P&gt;Given this load script:&lt;/P&gt;
&lt;P&gt;Table:&lt;/P&gt;
&lt;P&gt;LOAD * Inline [&lt;/P&gt;
&lt;P&gt;ID,Item,Total,Pending&lt;/P&gt;
&lt;P&gt;A,A-1,10,8&lt;BR /&gt;A,A-2,12,7&lt;BR /&gt;B,B-1,190,124&lt;BR /&gt;C,C-1,18,2&lt;BR /&gt;C,C-2,100,60&lt;BR /&gt;D,D-1,2,2&lt;BR /&gt;D,D-2,10,8&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;I would like to get the Pending Rate (Sum of Pending/Sum of Total) for the IDs where the Sum of Total is &amp;gt;= 20. However, the value I am getting is as if I am not applying the condition that the Sum of Total is &amp;gt;= 20.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="adrianfer_0-1723597306555.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/170610i9E201CDD958AA0B0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="adrianfer_0-1723597306555.png" alt="adrianfer_0-1723597306555.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expression for Pending Rate for the second chart is :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If(Sum(Aggr(Sum(Total),ID))&amp;gt;=20, Sum(Pending)/Sum(Total))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached a sample file here.&lt;/P&gt;
&lt;P&gt;Appreciate all the help! Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 01:03:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476172#M100246</guid>
      <dc:creator>adrianfer</dc:creator>
      <dc:date>2024-08-14T01:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476314#M100263</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/20155"&gt;@adrianfer&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;see the result with the expression below:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Sum(Aggr(if(Sum(Total)&amp;gt;=20,Sum(Pending)/Sum(Total)),ID))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;- Matheus&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 13:30:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476314#M100263</guid>
      <dc:creator>MatheusC</dc:creator>
      <dc:date>2024-08-14T13:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476326#M100266</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/20155"&gt;@adrianfer&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Your condition doesn't work as expected because&amp;nbsp;&lt;SPAN&gt;Sum(Aggr(Sum(Total),ID)) returns the overall sum of the Total values across all IDs - the AGGR function returns an array of sum(Total) by ID, and then the Sum() function aggregates the array into a single number - 342 in your example.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In fact, you don't really need to use AGGR() if your chart includes ID as a dimension. In other instances, you would, but not here. In this chart, it's enough to add a simple IF condition like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;IF(sum(Total)&amp;gt;=20,&amp;nbsp;&lt;SPAN&gt;Sum(Pending)/Sum(Total))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If you wanted to apply the same condition to all measures, then you should add the same IF() to all of them.&lt;/P&gt;
&lt;P&gt;Allow me to invite you to the upcoming session of the &lt;A title="Masters Summit for Qlik" href="https://masterssummit.com" target="_blank" rel="noopener"&gt;Masters Summit for Qlik&lt;/A&gt; in Vienna, where I will be teaching Advanced Development Techniques, including advanced uses of AGGR(), Set Analysis, Data Modeling, Performance Optimization, and more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 15:00:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476326#M100266</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2024-08-14T15:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476393#M100274</link>
      <description>&lt;P&gt;That gives me this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="adrianfer_0-1723680546492.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/170646i387C458685948E3B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="adrianfer_0-1723680546492.png" alt="adrianfer_0-1723680546492.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Per ID is correct, but the Totals should be 201/330 = 60.9% right?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 00:09:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476393#M100274</guid>
      <dc:creator>adrianfer</dc:creator>
      <dc:date>2024-08-15T00:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476395#M100275</link>
      <description>&lt;P&gt;This one gives this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="adrianfer_1-1723681151218.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/170647iF887B666FA3E1E98/image-size/medium?v=v2&amp;amp;px=400" role="button" title="adrianfer_1-1723681151218.png" alt="adrianfer_1-1723681151218.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Per ID is correct, but the Totals should be 201/330 = 60.9%&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 00:19:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476395#M100275</guid>
      <dc:creator>adrianfer</dc:creator>
      <dc:date>2024-08-15T00:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476398#M100276</link>
      <description>&lt;P&gt;If you don't need to display 'D' which Total is less than 20, you can use this in the dimension and untick 'Include Null Values':&lt;BR /&gt;IF(AGGR(SUM(Total),ID) &amp;gt;= 20, ID)&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For measures,&lt;BR /&gt;Total: SUM(Total)&lt;BR /&gt;Pending: SUM(Pending)&lt;BR /&gt;Pending Rate: Column(2) / Column(1)&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 00:41:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476398#M100276</guid>
      <dc:creator>poklegoguy</dc:creator>
      <dc:date>2024-08-15T00:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476445#M100278</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/20155"&gt;@adrianfer&lt;/a&gt;&amp;nbsp; try below expression&lt;/P&gt;
&lt;P&gt;Sum({&amp;lt;ID={"=sum(Total)&amp;gt;=20"}&amp;gt;}Pending)/&lt;BR /&gt;Sum({&amp;lt;ID={"=sum(Total)&amp;gt;=20"}&amp;gt;}Total)&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 09:27:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476445#M100278</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-08-15T09:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentage based on conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476503#M100286</link>
      <description>&lt;P&gt;Well, you should either exclude the D from the chart (which is probably the best decision), and then the total should match the sum of lines, or you could use the AGGR function again, but this time correctly:&lt;BR /&gt;&lt;BR /&gt;sum(AGGR(&lt;SPAN&gt;IF(sum(Total)&amp;gt;=20,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Sum(Pending)), ID)) /&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;sum(AGGR(&lt;SPAN&gt;IF(sum(Total)&amp;gt;=20,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Sum(Total)), ID)) /&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In this formula, the product D will get excluded from the totals, even if it remains in the chart with all empty values.&lt;/P&gt;
&lt;P&gt;The Set Analysis with advanced search solution, suggested by &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp;, is also a very good one. It's limited to a single field (ID), but it works very well if this is all you need.&lt;/P&gt;
&lt;P&gt;As a separate note, I'd mention that depending on the nature of your objects (products, people, etc.) it may not be a good idea to calculate total % by summarizing all units and dividing the totals by each other. For example, if these are products, and one product could be a screw and another product could be a car,&amp;nbsp; - in this case I wouldn't want to sum up screws and cars in one total. In this case, I'd rather define the total % as an average of the individual percentages - but that's a different discussion altogether.&lt;/P&gt;
&lt;P&gt;Back to AGGR - it's a very powerful and the least understood function in Qlik. You can use it for very complex calculations, when you know how to use it right. For anyone who is interested in learning more - let me invite you again to the upcoming &lt;A href="https://masterssummit.com" target="_blank" rel="noopener"&gt;Masters Summit for Qlik&lt;/A&gt; in Vienna, where I'll be teaching advanced development topics, including the various complex scenarios with the AGGR() function and with advanced Set Analysis.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 14:30:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-percentage-based-on-conditions/m-p/2476503#M100286</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2024-08-15T14:30:49Z</dc:date>
    </item>
  </channel>
</rss>

