<?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 Using IF or set analysis inside AGGR function? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Using-IF-or-set-analysis-inside-AGGR-function/m-p/602009#M222600</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;tl;dr : How to write an expression that has IF condition inside an AGGR function, i.e.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;AGGR&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(field1)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;field2&lt;/SPAN&gt; = 60,1000))),&lt;SPAN class="s2"&gt;field2&lt;/SPAN&gt;))?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to add a row to my table if certain conditions are met (namely when there's no existing data and customer's lifetime is, say, 60 days). This works in a table that has customer lifetime as a dimension, but it fails when I remove the dimension and add it to the expression using AGGR function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table with one dimension &lt;EM&gt;cohort_age&lt;/EM&gt; and three columns : &lt;EM&gt;some_values&lt;/EM&gt;, &lt;EM&gt;add_value_if&lt;/EM&gt; and &lt;EM&gt;combined&lt;/EM&gt;. The first one (&lt;EM&gt;some_values&lt;/EM&gt;) is simply a sum of existing values. The second one (&lt;EM&gt;add_value_if&lt;/EM&gt;) adds a row when I don't have data for a given lifetime. And the third one combines these two into one time series using &lt;EM&gt;&amp;amp;&lt;/EM&gt; operator. It works and looks like this :&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Table1.jpg" class="jive-image" height="309" src="https://community.qlik.com/legacyfs/online/56589_Table1.jpg" style="width: 350px; height: 308.7903225806452px;" width="350" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I remove the &lt;EM&gt;cohort_age&lt;/EM&gt; dimension and add it into the expression using AGGR function things start to fall apart.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Table2.jpg" class="jive-image" height="54" src="https://community.qlik.com/legacyfs/online/56590_Table2.jpg" style="width: 335px; height: 54.48096885813149px;" width="335" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Working Expressions (in a table with explicit dimension)&lt;/P&gt;&lt;P&gt;&lt;EM&gt;some_values&lt;/EM&gt; : sum(duu)&lt;/P&gt;&lt;P&gt;&lt;EM&gt;add_value_if&lt;/EM&gt; : IF(sum(duu)=0,only({1}IF(cohort_age = 60,1000)))&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;&lt;EM&gt;combined : &lt;/EM&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;) &amp;amp; &lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;sum&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60,1000))) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Failing expression (in a table with implicit dimension)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;&lt;EM&gt;add_value_if:&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;AGGR&lt;/SPAN&gt;(&lt;BR /&gt;&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;sum&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60,1000)))&lt;BR /&gt;,&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt;))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;combined :&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;AGGR&lt;/SPAN&gt;(&lt;BR /&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)&lt;BR /&gt;&amp;amp;&lt;BR /&gt;&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;sum&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60,1000)))&lt;BR /&gt;,&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt;)) &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried to use set analysis -- &lt;SPAN class="s1"&gt;&lt;EM&gt;only&lt;/EM&gt;&lt;/SPAN&gt;&lt;EM&gt;({1 &amp;lt;&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60, cohort_age={&lt;SPAN class="s2"&gt;"=SUM(duu)=0"&lt;/SPAN&gt;}&amp;gt;} 1000 ) --&lt;/EM&gt; but the results weren't any different. So I'd much appreciate if you guys could point me to the right direction &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Joonas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Apr 2014 09:46:21 GMT</pubDate>
    <dc:creator />
    <dc:date>2014-04-04T09:46:21Z</dc:date>
    <item>
      <title>Using IF or set analysis inside AGGR function?</title>
      <link>https://community.qlik.com/t5/QlikView/Using-IF-or-set-analysis-inside-AGGR-function/m-p/602009#M222600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;tl;dr : How to write an expression that has IF condition inside an AGGR function, i.e.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;AGGR&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(field1)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;field2&lt;/SPAN&gt; = 60,1000))),&lt;SPAN class="s2"&gt;field2&lt;/SPAN&gt;))?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to add a row to my table if certain conditions are met (namely when there's no existing data and customer's lifetime is, say, 60 days). This works in a table that has customer lifetime as a dimension, but it fails when I remove the dimension and add it to the expression using AGGR function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table with one dimension &lt;EM&gt;cohort_age&lt;/EM&gt; and three columns : &lt;EM&gt;some_values&lt;/EM&gt;, &lt;EM&gt;add_value_if&lt;/EM&gt; and &lt;EM&gt;combined&lt;/EM&gt;. The first one (&lt;EM&gt;some_values&lt;/EM&gt;) is simply a sum of existing values. The second one (&lt;EM&gt;add_value_if&lt;/EM&gt;) adds a row when I don't have data for a given lifetime. And the third one combines these two into one time series using &lt;EM&gt;&amp;amp;&lt;/EM&gt; operator. It works and looks like this :&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Table1.jpg" class="jive-image" height="309" src="https://community.qlik.com/legacyfs/online/56589_Table1.jpg" style="width: 350px; height: 308.7903225806452px;" width="350" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I remove the &lt;EM&gt;cohort_age&lt;/EM&gt; dimension and add it into the expression using AGGR function things start to fall apart.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Table2.jpg" class="jive-image" height="54" src="https://community.qlik.com/legacyfs/online/56590_Table2.jpg" style="width: 335px; height: 54.48096885813149px;" width="335" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Working Expressions (in a table with explicit dimension)&lt;/P&gt;&lt;P&gt;&lt;EM&gt;some_values&lt;/EM&gt; : sum(duu)&lt;/P&gt;&lt;P&gt;&lt;EM&gt;add_value_if&lt;/EM&gt; : IF(sum(duu)=0,only({1}IF(cohort_age = 60,1000)))&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;&lt;EM&gt;combined : &lt;/EM&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;) &amp;amp; &lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;sum&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60,1000))) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Failing expression (in a table with implicit dimension)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;&lt;EM&gt;add_value_if:&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;AGGR&lt;/SPAN&gt;(&lt;BR /&gt;&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;sum&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60,1000)))&lt;BR /&gt;,&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt;))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;combined :&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;AGGR&lt;/SPAN&gt;(&lt;BR /&gt;&lt;SPAN class="s1"&gt;SUM&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)&lt;BR /&gt;&amp;amp;&lt;BR /&gt;&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;sum&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;duu&lt;/SPAN&gt;)=0,&lt;SPAN class="s1"&gt;only&lt;/SPAN&gt;({1}&lt;SPAN class="s1"&gt;IF&lt;/SPAN&gt;(&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60,1000)))&lt;BR /&gt;,&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt;)) &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried to use set analysis -- &lt;SPAN class="s1"&gt;&lt;EM&gt;only&lt;/EM&gt;&lt;/SPAN&gt;&lt;EM&gt;({1 &amp;lt;&lt;SPAN class="s2"&gt;cohort_age&lt;/SPAN&gt; = 60, cohort_age={&lt;SPAN class="s2"&gt;"=SUM(duu)=0"&lt;/SPAN&gt;}&amp;gt;} 1000 ) --&lt;/EM&gt; but the results weren't any different. So I'd much appreciate if you guys could point me to the right direction &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Joonas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Apr 2014 09:46:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-IF-or-set-analysis-inside-AGGR-function/m-p/602009#M222600</guid>
      <dc:creator />
      <dc:date>2014-04-04T09:46:21Z</dc:date>
    </item>
  </channel>
</rss>

