<?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 Aggregation with multiple if conditions and Average in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Aggregation-with-multiple-if-conditions-and-Average/m-p/1233592#M392801</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We're trying to build a simulation chart where a change in value entered in input boxes affects the chart, but based on certain conditions.&lt;/P&gt;&lt;P&gt;More details in the attached Excel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;The only dimension in the chart is the monthname.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14876664945358488" jivemacro_uid="_14876664945358488"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;=Date(MonthStart(TblContracts.Shipment_Monthname),'MMM-YY')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;To calculate the margin value in the chart, we wrote a simple aggregation expression.&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14876662742509108 jive_text_macro" jivemacro_uid="_14876662742509108"&gt;
&lt;P&gt;((Aggr(sum(TblContracts.SP*TblContracts.OutstandingQuantity), TblContracts.Shipment_Monthname))&lt;/P&gt;
&lt;P&gt;-(Aggr(sum(TblContracts.CP*TblContracts.OutstandingQuantity), TblContracts.Shipment_Monthname)))/&lt;/P&gt;
&lt;P&gt;(Aggr(sum(TblContracts.SP*TblContracts.OutstandingQuantity), TblContracts.Shipment_Monthname))&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This expression will ensure that irrespective of the SP_Index or CP_Index the Margin value for each month is evaluated simply based on the available months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As mentioned in the excel the entry zones will affect only those months with the index ID. I managed to get it work for 1 combination of SP_Index and CP_Index. Here's the expression:&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14876680356028755" jivemacro_uid="_14876680356028755"&gt;
&lt;P&gt;If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname,&lt;/P&gt;
&lt;P&gt;(Avg((Aggr(sum(If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.SP+B1)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname) - Aggr(sum(If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Unit_CP+A1)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname))/(Aggr(sum(If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Net_Unit_SP+B1)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname)))),&lt;/P&gt;
&lt;P&gt;If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname,&lt;/P&gt;
&lt;P&gt;(Avg((Aggr(sum(If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Net_Unit_SP+B2)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname) - Aggr(sum(If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Unit_CP+A2)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname))/(Aggr(sum(If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Net_Unit_SP+B2)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname))))&lt;/P&gt;
&lt;P&gt;))&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A1,A2 &amp;amp; B1,B2 are variables that represent jan and feb values respectively.&lt;/P&gt;&lt;P&gt;I am unable to include the rest of the index variables into this expression for each month - the variables C1, C2, D1, D2,E1, E2 are to be included to give an aggregated value for each month in the chart.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if you need more details.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Feb 2017 09:01:02 GMT</pubDate>
    <dc:creator />
    <dc:date>2017-02-21T09:01:02Z</dc:date>
    <item>
      <title>Aggregation with multiple if conditions and Average</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-with-multiple-if-conditions-and-Average/m-p/1233592#M392801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We're trying to build a simulation chart where a change in value entered in input boxes affects the chart, but based on certain conditions.&lt;/P&gt;&lt;P&gt;More details in the attached Excel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;The only dimension in the chart is the monthname.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14876664945358488" jivemacro_uid="_14876664945358488"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;=Date(MonthStart(TblContracts.Shipment_Monthname),'MMM-YY')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;To calculate the margin value in the chart, we wrote a simple aggregation expression.&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14876662742509108 jive_text_macro" jivemacro_uid="_14876662742509108"&gt;
&lt;P&gt;((Aggr(sum(TblContracts.SP*TblContracts.OutstandingQuantity), TblContracts.Shipment_Monthname))&lt;/P&gt;
&lt;P&gt;-(Aggr(sum(TblContracts.CP*TblContracts.OutstandingQuantity), TblContracts.Shipment_Monthname)))/&lt;/P&gt;
&lt;P&gt;(Aggr(sum(TblContracts.SP*TblContracts.OutstandingQuantity), TblContracts.Shipment_Monthname))&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This expression will ensure that irrespective of the SP_Index or CP_Index the Margin value for each month is evaluated simply based on the available months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As mentioned in the excel the entry zones will affect only those months with the index ID. I managed to get it work for 1 combination of SP_Index and CP_Index. Here's the expression:&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14876680356028755" jivemacro_uid="_14876680356028755"&gt;
&lt;P&gt;If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname,&lt;/P&gt;
&lt;P&gt;(Avg((Aggr(sum(If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.SP+B1)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname) - Aggr(sum(If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Unit_CP+A1)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname))/(Aggr(sum(If(MonthName(vminShipmentDate)=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Net_Unit_SP+B1)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname)))),&lt;/P&gt;
&lt;P&gt;If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname,&lt;/P&gt;
&lt;P&gt;(Avg((Aggr(sum(If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Net_Unit_SP+B2)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname) - Aggr(sum(If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Unit_CP+A2)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname))/(Aggr(sum(If(MonthName(AddMonths(vminShipmentDate,1))=TblContracts.Shipment_Monthname and TblContracts.CP_Index='A' and TblContracts.SP_Index='B',(TblContracts.Net_Unit_SP+B2)*TblContracts.OutstandingQuantity)), TblContracts.Shipment_Monthname))))&lt;/P&gt;
&lt;P&gt;))&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A1,A2 &amp;amp; B1,B2 are variables that represent jan and feb values respectively.&lt;/P&gt;&lt;P&gt;I am unable to include the rest of the index variables into this expression for each month - the variables C1, C2, D1, D2,E1, E2 are to be included to give an aggregated value for each month in the chart.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if you need more details.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2017 09:01:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-with-multiple-if-conditions-and-Average/m-p/1233592#M392801</guid>
      <dc:creator />
      <dc:date>2017-02-21T09:01:02Z</dc:date>
    </item>
  </channel>
</rss>

