<?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: Aggregation Conundrum in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642500#M235389</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've thought about it some more, and believe this might be the way to go -- on each line, add a flag to indicate a sale (by location/year/month/customer/item) during the previous year, and a second flag to indicate a sale during the following year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As my QlikView scripting skills are still elementary, I'd be curious to hear how one might accomplish this. I believe I would create a second table that does the required aggregation and adds the flags, rather than trying to add flags to the existing Invoices table. I don't want to create redundancy or do something that works against QlikView, if that makes sense. I'd like to keep it simple.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Jun 2014 19:25:32 GMT</pubDate>
    <dc:creator />
    <dc:date>2014-06-06T19:25:32Z</dc:date>
    <item>
      <title>Aggregation Conundrum</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642495#M235384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello! I need some advice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I load from source a table called Invoices that looks (more or less) like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Location | Year | Month | Customer| Item | Sales | Etc... &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a pivot table in QlikView with dimensions of Location and Month. The expressions are "Sales for Selected Year" and "Sales for Previous Year"; they look like this:&lt;BR /&gt;&lt;STRONG&gt;Sum({&amp;lt;Year={$(=Max(Year))} &amp;gt;} [Sales]) &lt;/STRONG&gt;&lt;BR /&gt;and &lt;BR /&gt;&lt;STRONG&gt;Sum({&amp;lt;Year={$(=Max(Year - 1))} &amp;gt;} [Sales])&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Year is a single select listbox.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As such, it works fine. But here's the caveat:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;The only sales that should contribute to the sum are those where there are nonzero sales during both time periods&lt;/SPAN&gt;. In SQL terms, suppose we're comparing years 2013 and 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Select Location, Year, Month, Customer, Item, SUM(Sales) &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from Invoices&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;where Year in (2013, 2012) &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;group by Location, Year, Month, Customer, Item&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BOTH of the lines below should contribute to the total.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NYC | 2013 | May | ACME | ITEM1 | $500&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NYC | 2012 | May | ACME | ITEM1 | $400&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However NEITHER of the lines below should contribute to the total (because there were no sales of ITEM5 to ACME from location NYC during May 2012).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NYC | 2013 | May | ACME | ITEM5 | $200&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NYC | 2012 | May | ACME | ITEM5 | $0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there's this arbitrary sort of intermediate grouping and filtering that needs to happen. I thought of creating a separate aggregate table from the main Invoices table, and working off of that, but it seems cumbersome. Any thoughts? Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 12:26:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642495#M235384</guid>
      <dc:creator />
      <dc:date>2014-06-06T12:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Conundrum</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642496#M235385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you set a flag = 1 when there are sales for a month or 0 if not&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sum({&amp;lt;Year={$(=Max(Year))} &amp;gt;} [Sales] * Flag)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;best regards&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Chris&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 12:54:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642496#M235385</guid>
      <dc:creator />
      <dc:date>2014-06-06T12:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Conundrum</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642497#M235386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Chris. Problem with that is it still has to be dynamic. Suppose you have this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NYC | 2014 | May | ACME | ITEM5 | $300&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NYC | 2013 | May | ACME | ITEM5 | $200&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NYC | 2012 | May | ACME | ITEM5 | $0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May 2013 sales would appear with a selection of year 2014 (and previous year 2013) but would NOT appear with a selection of 2013 (and previous year 2012).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 13:23:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642497#M235386</guid>
      <dc:creator />
      <dc:date>2014-06-06T13:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Conundrum</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642498#M235387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes Brian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tricky, you can then set 2 flags for yera and previous year&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you set a flag comparing year by month to month&amp;nbsp; lik&lt;/P&gt;&lt;P&gt;for may 2014 / may 2013&amp;nbsp; currentflag = 1, previousflag = 1&lt;/P&gt;&lt;P&gt;for may 2013 / may 2012 currentflag=1 , previousflag = 0&lt;/P&gt;&lt;P&gt;for may 2012 / may 2011 currentflag =0, previousflag = ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 13:38:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642498#M235387</guid>
      <dc:creator />
      <dc:date>2014-06-06T13:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Conundrum</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642499#M235388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, that's a thought. How would I go about adding this, do you think? I think it would be a change to my script after I load the Invoices table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 15:20:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642499#M235388</guid>
      <dc:creator />
      <dc:date>2014-06-06T15:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Conundrum</title>
      <link>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642500#M235389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've thought about it some more, and believe this might be the way to go -- on each line, add a flag to indicate a sale (by location/year/month/customer/item) during the previous year, and a second flag to indicate a sale during the following year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As my QlikView scripting skills are still elementary, I'd be curious to hear how one might accomplish this. I believe I would create a second table that does the required aggregation and adds the flags, rather than trying to add flags to the existing Invoices table. I don't want to create redundancy or do something that works against QlikView, if that makes sense. I'd like to keep it simple.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 19:25:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggregation-Conundrum/m-p/642500#M235389</guid>
      <dc:creator />
      <dc:date>2014-06-06T19:25:32Z</dc:date>
    </item>
  </channel>
</rss>

