<?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 set analysis with sum(if()) in the script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391141#M697543</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a set analayis in a chart which is computing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if the AVG of the months 1 to 3 is bigger than 1.1*AVG of months 4 to 6, the AVG of months 1 to 3 is taken into consideration, otherwise the AVG of months 1 to 6.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the set analysis looks like follow:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596495606854161" jivemacro_uid="_13596495606854161"&gt;&lt;P&gt;if((Sum({$&amp;lt;BUCKET={"&amp;gt;=-3 &amp;lt;=-1"}&amp;gt;} BucketQty)/3) &amp;gt; 1.01*(Sum({$&amp;lt;BUCKET={"&amp;gt;=-6 &amp;lt;=-4"}&amp;gt;} BucketQty)/3),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(Sum({$&amp;lt;BUCKET={"&amp;gt;=-3 &amp;lt;=-1"}&amp;gt;} BucketQty)/3),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(Sum({$&amp;lt;BUCKET={"&amp;gt;=-6 &amp;lt;=-1"}&amp;gt;} BucketQty)/6))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now,I am trying to do this in-script for different reasons.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the approach with LET, i.e.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596496069029146" jivemacro_uid="_13596496069029146"&gt;&lt;P&gt;LET vTrend=if((Sum({$&amp;lt;BUCKET={"&amp;gt;=-3 &amp;lt;=-1"}&amp;gt;} BucketQty)/3) &amp;gt; [...]&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the approach of SUM(If(condition, value))&lt;/P&gt;&lt;P&gt;but still not working&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596500502893496" jivemacro_uid="_13596500502893496"&gt;&lt;P&gt;if(&lt;/P&gt;&lt;P&gt;Sum(if( BUCKET&amp;gt;=(-3) and BUCKET&amp;lt;=(-1)), BucketQty/3) &amp;gt; 1.01*(Sum(if(BUCKET&amp;gt;=(-6) and BUCKET&amp;lt;=(-4)), BucketQty/3)),&lt;/P&gt;&lt;P&gt;Sum(if(BUCKET&amp;gt;=-3 and BUCKET &amp;lt;=-1), BucketQty/3),&lt;/P&gt;&lt;P&gt;Sum(BUCKET&amp;gt;=-6 and BUCKET &amp;lt;=-1), BucketQty/6) as CalcTrend;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it thus possible to achieve that set anallysis above mentioned, in the script?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Jan 2013 16:36:36 GMT</pubDate>
    <dc:creator />
    <dc:date>2013-01-31T16:36:36Z</dc:date>
    <item>
      <title>set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391141#M697543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a set analayis in a chart which is computing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if the AVG of the months 1 to 3 is bigger than 1.1*AVG of months 4 to 6, the AVG of months 1 to 3 is taken into consideration, otherwise the AVG of months 1 to 6.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the set analysis looks like follow:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596495606854161" jivemacro_uid="_13596495606854161"&gt;&lt;P&gt;if((Sum({$&amp;lt;BUCKET={"&amp;gt;=-3 &amp;lt;=-1"}&amp;gt;} BucketQty)/3) &amp;gt; 1.01*(Sum({$&amp;lt;BUCKET={"&amp;gt;=-6 &amp;lt;=-4"}&amp;gt;} BucketQty)/3),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(Sum({$&amp;lt;BUCKET={"&amp;gt;=-3 &amp;lt;=-1"}&amp;gt;} BucketQty)/3),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(Sum({$&amp;lt;BUCKET={"&amp;gt;=-6 &amp;lt;=-1"}&amp;gt;} BucketQty)/6))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now,I am trying to do this in-script for different reasons.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the approach with LET, i.e.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596496069029146" jivemacro_uid="_13596496069029146"&gt;&lt;P&gt;LET vTrend=if((Sum({$&amp;lt;BUCKET={"&amp;gt;=-3 &amp;lt;=-1"}&amp;gt;} BucketQty)/3) &amp;gt; [...]&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the approach of SUM(If(condition, value))&lt;/P&gt;&lt;P&gt;but still not working&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596500502893496" jivemacro_uid="_13596500502893496"&gt;&lt;P&gt;if(&lt;/P&gt;&lt;P&gt;Sum(if( BUCKET&amp;gt;=(-3) and BUCKET&amp;lt;=(-1)), BucketQty/3) &amp;gt; 1.01*(Sum(if(BUCKET&amp;gt;=(-6) and BUCKET&amp;lt;=(-4)), BucketQty/3)),&lt;/P&gt;&lt;P&gt;Sum(if(BUCKET&amp;gt;=-3 and BUCKET &amp;lt;=-1), BucketQty/3),&lt;/P&gt;&lt;P&gt;Sum(BUCKET&amp;gt;=-6 and BUCKET &amp;lt;=-1), BucketQty/6) as CalcTrend;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it thus possible to achieve that set anallysis above mentioned, in the script?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 16:36:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391141#M697543</guid>
      <dc:creator />
      <dc:date>2013-01-31T16:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391142#M697544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;you have to use this syntax in script langiage&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(if..then, elseif..then, else end if)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and not:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(condition,'','')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Giampiero&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 16:41:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391142#M697544</guid>
      <dc:creator />
      <dc:date>2013-01-31T16:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391143#M697545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry,&lt;/P&gt;&lt;P&gt;if you're calculating for fields you're right.&lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/silly.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 16:45:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391143#M697545</guid>
      <dc:creator />
      <dc:date>2013-01-31T16:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391144#M697546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;giampiero.cina wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry,&lt;/P&gt;&lt;P&gt;if you're calculating for fields you're right.&lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/silly.png" /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;nice &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but then it is still not working!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;forgot to mention, this table is made of thousands of rows, where each one of them is an item.&lt;/P&gt;&lt;P&gt;For each item there are 12 buckets, i basically to have a further field being the weighted average described as above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 16:58:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391144#M697546</guid>
      <dc:creator />
      <dc:date>2013-01-31T16:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391145#M697547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Have you tried&amp;nbsp; in this way :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (if(BUCKET=&amp;gt;=-3 and BUCKET&amp;lt;=-1,sum(BucketQty)/3) &amp;gt; if(BUCKET=&amp;gt;=-6 and BUCKET&amp;lt;=-4,sum(BucketQty)/3) * 1.01, if(BUCKET=&amp;gt;=-3 and BUCKET&amp;lt;=-1,sum(BucketQty)/3), if(BUCKET=&amp;gt;=-6 and BUCKET&amp;lt;=-1,sum(BucketQty)/6)) as CalcTrend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Giampiero&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 17:00:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391145#M697547</guid>
      <dc:creator />
      <dc:date>2013-01-31T17:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391146#M697548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I needed to change a bit your script to have the colours appear in the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(namely, from &lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596529914489480" jivemacro_uid="_13596529914489480"&gt;&lt;P&gt;&lt;SPAN style="color: #737373; font-family: Arial; background-color: #ffffff;"&gt;BUCKET=&amp;gt;=-3&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596529996467480" jivemacro_uid="_13596529996467480"&gt;&lt;P&gt;&lt;SPAN style="color: #737373; font-family: Arial; background-color: #ffffff;"&gt;BUCKET&amp;gt;=-3&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;and so on...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I got the following error when reloading&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13596529672339368" jivemacro_uid="_13596529672339368"&gt;&lt;P&gt;Invalid expression&lt;/P&gt;&lt;P&gt;BucketDemand:&lt;/P&gt;&lt;P&gt;LOAD *,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (if(BUCKET&amp;gt;=-3 and BUCKET&amp;lt;=-1,sum(BucketQty)/3) &amp;gt; if(BUCKET&amp;gt;=-6 and BUCKET&amp;lt;=-4,sum(BucketQty)/3) * 1.01,&lt;/P&gt;&lt;P&gt;if(BUCKET&amp;gt;=-3 and BUCKET&amp;lt;=-1,sum(BucketQty)/3),&lt;/P&gt;&lt;P&gt;if(BUCKET&amp;gt;=-6 and BUCKET&amp;lt;=-1,sum(BucketQty)/6)) as CalcTrend&lt;/P&gt;&lt;P&gt;RESIDENT BucketDemandTemp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so still not good.... &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 17:23:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391146#M697548</guid>
      <dc:creator />
      <dc:date>2013-01-31T17:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391147#M697549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;could you post a qvw to see how to help you ?&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Giampiero&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Feb 2013 09:11:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391147#M697549</guid>
      <dc:creator />
      <dc:date>2013-02-01T09:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: set analysis with sum(if()) in the script</title>
      <link>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391148#M697550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think the problem now is not the IF command but using the Sum function you have to use the group by.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attach a simple example to understand:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD Id, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FieldA, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum(FieldB) as SumFieldB, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FieldC&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;&lt;C&gt;&lt;/C&gt;&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is test)&lt;/P&gt;&lt;P&gt;group by Id,FieldA,FieldC;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;group by is obligatory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suppose that adding group by in your table you could solve your problem.&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Giampiero&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Feb 2013 10:07:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/set-analysis-with-sum-if-in-the-script/m-p/391148#M697550</guid>
      <dc:creator />
      <dc:date>2013-02-01T10:07:06Z</dc:date>
    </item>
  </channel>
</rss>

