<?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: Set analysis - using 4 variables to compare date ranges 1 year apart in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Set-analysis-using-4-variables-to-compare-date-ranges-1-year/m-p/1668276#M449295</link>
    <description>&lt;P&gt;I also am looking at this type of problem.&amp;nbsp; Is there anyone out there that has done this???&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jan 2020 20:02:26 GMT</pubDate>
    <dc:creator>tim_at_ford</dc:creator>
    <dc:date>2020-01-22T20:02:26Z</dc:date>
    <item>
      <title>Set analysis - using 4 variables to compare date ranges 1 year apart</title>
      <link>https://community.qlik.com/t5/QlikView/Set-analysis-using-4-variables-to-compare-date-ranges-1-year/m-p/780463#M276541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello experts - I hope you can help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created a table which shows sales quantities for each salesperson within a date range which is set using 2 calendar controls (start and end dates for the range)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The date on the 'start' calendar sets variable vStartTranDate, and the date on the 'end' calendar sets variable vEndTranDate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expression for the sales quantity column (which works fine) is this:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;= sum({&amp;lt;SourceOfSale={'CallCentre'}, DateOfTransaction= { "$(= '&amp;gt;=' &amp;amp; date(vTranStartDate,'YYYY-MM-DD') &amp;amp; '&amp;lt;=' &amp;amp; date(vTranEndDate,'YYYY-MM-DD'))"&amp;nbsp; } &amp;gt;} SalesQuantity)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the next column to be the same, but for transaction date range 1 year back from the user's chosen start and end dates&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First I setup two variables to derive the right range (vOneYearBeforeTranStartDate &amp;amp; vOneYearBeforeEndStartDate) which simply use &lt;EM&gt;AddYears&lt;/EM&gt; to subtract 1 year from each of vStartTranDate &amp;amp; vEndTranDate&lt;/P&gt;&lt;P&gt;Then I added the new column with this expression:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;= sum( { $ &amp;lt;&lt;EM&gt;SourceOfSale={'CallCentre'}&lt;/EM&gt;, DateOfTransaction= { "$(= '&amp;gt;=' &amp;amp; date(vOneYearBeforeTranStartDate,'YYYY-MM-DD') &amp;amp; '&amp;lt;=' &amp;amp; date(vOneYearBeforeTranEndDate,'YYYY-MM-DD'))"&amp;nbsp; } &amp;gt; } &lt;EM&gt;SalesQuantity&lt;/EM&gt;)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This produced zeroes, this must be because within the current selection there is no data for the earlier date range. ie the user selects a range from December 17th 2013 to January 16th 2014, so data from 1 year before is excluded. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So then I tried replacing &lt;EM&gt;= sum( { &lt;STRONG&gt;$&lt;/STRONG&gt; &amp;lt;&lt;EM&gt;SourceOfSale={'CallCentre'} &lt;/EM&gt;&lt;/EM&gt;etc with &lt;EM&gt;= sum( { &lt;STRONG&gt;1&lt;/STRONG&gt; &amp;lt;&lt;EM&gt;SourceOfSale={'CallCentre'} &lt;/EM&gt;&lt;/EM&gt;which kind of works but not really because it remains unaffected by further selections on other fields, which is not what I want&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I tried -&lt;/P&gt;&lt;P&gt;&lt;EM&gt;= sum( { $ &amp;lt;&lt;EM&gt;&lt;STRONG&gt;DateOfTransaction=&lt;/STRONG&gt;, &lt;/EM&gt;&lt;EM&gt;SourceOfSale={'CallCentre'}&lt;/EM&gt;, DateOfTransaction= { "$(= '&amp;gt;=' &amp;amp; date(vOneYearBeforeTranStartDate,'YYYY-MM-DD') &amp;amp; '&amp;lt;=' &amp;amp; date(vOneYearBeforeTranEndDate,'YYYY-MM-DD'))"&amp;nbsp; } &amp;gt; } &lt;EM&gt;SalesQuantity&lt;/EM&gt;)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;- thinking it would ignore the user's date selection and instead respect only the &lt;EM&gt;vOneYearBefore... &lt;/EM&gt; variables - just more zeroes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only other suggestion I've seen that looks vaguely helpful is to use something like &lt;/P&gt;&lt;P&gt;&lt;EM&gt;Sum( { $ &amp;lt; Year = { $ (=Only(Year)-1 } &amp;gt; } &lt;EM&gt;SalesQuantity ) &lt;/EM&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;which would be fine until you get into ranges which span more than year (like in my December 17th 2013 to January 16th 2014 example)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's a lot of reading out there on this, but it seems geared to the logic that would make that last theory work, and that doesn't help me with the scenario of free date selection rather than set years/quarters/months. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At this point any advice would be gratefully received. Thank you. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 13:41:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Set-analysis-using-4-variables-to-compare-date-ranges-1-year/m-p/780463#M276541</guid>
      <dc:creator />
      <dc:date>2014-11-06T13:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis - using 4 variables to compare date ranges 1 year apart</title>
      <link>https://community.qlik.com/t5/QlikView/Set-analysis-using-4-variables-to-compare-date-ranges-1-year/m-p/1668276#M449295</link>
      <description>&lt;P&gt;I also am looking at this type of problem.&amp;nbsp; Is there anyone out there that has done this???&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 20:02:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Set-analysis-using-4-variables-to-compare-date-ranges-1-year/m-p/1668276#M449295</guid>
      <dc:creator>tim_at_ford</dc:creator>
      <dc:date>2020-01-22T20:02:26Z</dc:date>
    </item>
  </channel>
</rss>

