<?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 Re: Understanding of set expression combined with aggregated function in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704174#M53983</link>
    <description>&lt;P&gt;So, to make sure you understand, I want to start by telling that this will work too if you don't select a single value in year field.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max(Aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and here is why&lt;/P&gt;&lt;P&gt;1) Nothing is selected in Year and assuming max year in the data is 2020&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;All Years&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Selected 2020 (also the max year)&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;2020&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;No intersection&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now changing the expression to this&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max({&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1) Nothing is selected in Year and assuming max year in the data is 2020&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Selected 2020 (also the max year)&lt;/P&gt;&lt;TABLE border="1" width="768px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also try this&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max({&amp;lt;Year&amp;gt;} Aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1) Nothing is selected in Year and assuming max year in the data is 2020&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;All Years&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Selected 2020 (also the max year)&lt;/P&gt;&lt;TABLE border="1" width="768px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;All Years&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does it make sense?&lt;/P&gt;</description>
    <pubDate>Thu, 21 May 2020 13:25:15 GMT</pubDate>
    <dc:creator>sunny_talwar</dc:creator>
    <dc:date>2020-05-21T13:25:15Z</dc:date>
    <item>
      <title>Understanding of set expression combined with aggregated function</title>
      <link>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704169#M53981</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I hope all is good!&lt;/P&gt;&lt;P&gt;I have an example which is hard for me to grasp. For instance I have the following table:&lt;/P&gt;&lt;TABLE border="0" width="348" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="87" height="21"&gt;Company&lt;/TD&gt;&lt;TD width="87"&gt;Year&lt;/TD&gt;&lt;TD width="87"&gt;Item&lt;/TD&gt;&lt;TD width="87"&gt;Sale&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;A&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;Smartphone&lt;/TD&gt;&lt;TD&gt;6000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;A&lt;/TD&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;Tools&lt;/TD&gt;&lt;TD&gt;4000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;A&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;Haircut&lt;/TD&gt;&lt;TD&gt;7000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;B&lt;/TD&gt;&lt;TD&gt;2017&lt;/TD&gt;&lt;TD&gt;Bolts&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;B&lt;/TD&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;Pen&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;B&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;Smartphone&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;C&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;Tools&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;C&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;Haircut&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="21"&gt;C&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;Harddrive&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To have the sum(sale) is a no brainer. If I want the top selling product for each company it is also understandable:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max ( aggr ( sum ( Sale ), Company , Item) )&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But when it comes to a added set expression to always return me the top selling product for the PREVIOUS YEAR I implemented a "set expression":&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;=Max({&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;As you can see, the set expression were used twice, once for MAX function and the other time for AGGR. And that is where I get my numbers, I just don't understand why.&amp;nbsp; Why I need the &lt;FONT color="#339966"&gt;(Max Year-1 )&lt;/FONT&gt; twice?&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;For me the following makes more sense , but it simply wouldn't return what I want:&amp;nbsp;= Max( aggr&lt;FONT color="#3366FF"&gt;(sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale)&lt;/FONT&gt;, Company , Item) )&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;The last one would be simply a variation of&amp;nbsp; "=Max ( aggr ( sum ( Sale ), Company , Item) )" with an added "give me the last year values " command. Only the long one with two set expression works out.&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I hope someone can explain to me in plain words.&amp;nbsp; And also the differences.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stay safe. Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 13:13:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704169#M53981</guid>
      <dc:creator>Applicable88</dc:creator>
      <dc:date>2020-05-21T13:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of set expression combined with aggregated function</title>
      <link>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704174#M53983</link>
      <description>&lt;P&gt;So, to make sure you understand, I want to start by telling that this will work too if you don't select a single value in year field.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max(Aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and here is why&lt;/P&gt;&lt;P&gt;1) Nothing is selected in Year and assuming max year in the data is 2020&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;All Years&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Selected 2020 (also the max year)&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;2020&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;No intersection&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now changing the expression to this&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max({&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1) Nothing is selected in Year and assuming max year in the data is 2020&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Selected 2020 (also the max year)&lt;/P&gt;&lt;TABLE border="1" width="768px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also try this&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;=Max({&amp;lt;Year&amp;gt;} Aggr (sum( {&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;} Sale),Company,Item))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1) Nothing is selected in Year and assuming max year in the data is 2020&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;All Years&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;TD width="25%"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Selected 2020 (also the max year)&lt;/P&gt;&lt;TABLE border="1" width="768px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;Set Analysis for Max&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Set Analysis for Sum&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;Intersection of the two sets&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="382.727px" height="24px"&gt;All Years&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;TD width="191.818px" height="24px"&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does it make sense?&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 13:25:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704174#M53983</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2020-05-21T13:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of set expression combined with aggregated function</title>
      <link>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704374#M54002</link>
      <description>&lt;P&gt;Hey Sunny_Talwar!&lt;/P&gt;&lt;P&gt;as always real MVP :).&lt;/P&gt;&lt;P&gt;I still had to read it over and over, but now I got it. Thank you so much for providing me with all the infos and alternatives. It really helped me with my understanding. Many will benefit from your&amp;nbsp; function examples.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a great day buddy and stay safe!&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 12:02:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Understanding-of-set-expression-combined-with-aggregated/m-p/1704374#M54002</guid>
      <dc:creator>Applicable88</dc:creator>
      <dc:date>2020-05-22T12:02:12Z</dc:date>
    </item>
  </channel>
</rss>

