<?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: Client fidelity check in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748108#M664530</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ernesto,&lt;/P&gt;&lt;P&gt;what I was saying is that if you remove the 2015 date in your previous script, it still gives you a flag value setted to 1 for the customer (I think it's an error). Anyway &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I can study and work using the code you posted, so thank you so much!!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Jan 2015 14:41:18 GMT</pubDate>
    <dc:creator />
    <dc:date>2015-01-07T14:41:18Z</dc:date>
    <item>
      <title>Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748099#M664520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I'm trying to create a script for qlikview but I have some problems.&lt;/P&gt;&lt;P&gt;I'd like to check if a customer bought items last four years (at least one per year). What I have right now:&lt;/P&gt;&lt;P&gt;-db table1 with ID_customer&lt;/P&gt;&lt;P&gt;-db table2 with ID_customer, purchase, date of purchase&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Es:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table1&lt;/P&gt;&lt;P&gt;ID_customer&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;14&lt;/P&gt;&lt;P&gt;15&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table2&lt;/P&gt;&lt;P&gt;ID_customer purchase date&lt;/P&gt;&lt;P&gt;1 car 12/01/2011&lt;/P&gt;&lt;P&gt;1 tires 12/01/2012&lt;/P&gt;&lt;P&gt;1 motor 18/04/2013&lt;/P&gt;&lt;P&gt;1 glass 19/09/2014&lt;/P&gt;&lt;P&gt;1 tires 12/01/2012&lt;/P&gt;&lt;P&gt;5 parfum 05/07/2009&lt;/P&gt;&lt;P&gt;10 water 30/11/2014&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I'd like create is a list with customers that bought last four years, in this example ID_customer 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help me?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Diego&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 11:48:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748099#M664520</guid>
      <dc:creator />
      <dc:date>2015-01-07T11:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748100#M664522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi you can create a list box with the expression:&lt;/P&gt;&lt;P&gt;=Aggr(DISTINCT Only({&amp;lt;date={'&amp;gt;$(=AddMonths(Today(), -48))'}&amp;gt;} ID_customer), ID_customer)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 12:02:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748100#M664522</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-01-07T12:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748101#M664523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thanks for the answer, but it's not what I'm trying to do. What I need is to know people that bought at least one item for each year (of the past X years). In your example, you find ID 1 (correct) and ID 10 that bought only last year&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 12:08:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748101#M664523</guid>
      <dc:creator />
      <dc:date>2015-01-07T12:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748102#M664524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is this can be a start for you?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;André Gomes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 12:16:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748102#M664524</guid>
      <dc:creator>agomes1971</dc:creator>
      <dc:date>2015-01-07T12:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748103#M664525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, then maybe something like:&lt;/P&gt;&lt;P&gt;=Aggr(If(Count({&amp;lt;date={'&amp;gt;$(=AddMonths(Today(), -48))'}&amp;gt;} DISTINCT Year(date))=4, ID_customer), ID_customer)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 12:18:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748103#M664525</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-01-07T12:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748104#M664526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you can do all the calculations on the script. Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Customers:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD * INLINE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 12&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 14&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 15&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Purchase:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD * INLINE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer, purchase, date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, car, 12/01/2011&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, tires, 12/01/2012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, motor, 18/04/2013&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, glass, 19/09/2014&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, tires,12/01/2012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 5, parfum, 05/07/2009&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 10, water, 30/11/2014&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, glass, 07/01/2015&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;PurchaseByYear:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; YEAR(date) as year,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF(YEAR(date) &amp;gt;= YEAR(TODAY())-4, 1, 0) AS FlagLastYears,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; COUNT(purchase) as TotalPurchase&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT Purchase&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;GROUP BY&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; YEAR(date),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF(YEAR(date) &amp;gt; YEAR(TODAY()-4), 1, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;ClientFidelity:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SUM(FlagLastYears) AS Fidelity&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT PurchaseByYear&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;WHERE TotalPurchase &amp;gt; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;GROUP BY ID_customer; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LEFT JOIN (Customers) LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF(Fidelity &amp;gt;= 4, 1, 0) AS Fidelity&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT ClientFidelity;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;DROP TABLE ClientFidelity;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;DROP TABLE PurchaseByYear;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will generate a flag field "Fidelity" in the customers table signaling if such customer purchased something in the past 4 years including current year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Ernesto.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 12:44:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748104#M664526</guid>
      <dc:creator>consenit</dc:creator>
      <dc:date>2015-01-07T12:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748105#M664527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ernesto,&lt;/P&gt;&lt;P&gt;thanks for the reply but it seems not to be working.. If you try to change &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'courier new', courier;"&gt;1, glass, 07/01/2015 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'courier new', courier;"&gt;to &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'courier new', courier;"&gt;1, glass, 07/01/2014, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'courier new', courier;"&gt;no customers should have the flag Fidelity settet to one (as no one bought on 2015).. But it still happens...&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:12:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748105#M664527</guid>
      <dc:creator />
      <dc:date>2015-01-07T14:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748106#M664528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i hope my answer as in somehow helped you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;André Gomes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:20:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748106#M664528</guid>
      <dc:creator>agomes1971</dc:creator>
      <dc:date>2015-01-07T14:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748107#M664529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I had to add an entry for at least one purchase in 2015 to make it work because my original calculation was based on the TODAY() function wich returns the current date. Don't worry: it's easy to fix though:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Customers:&lt;/P&gt;&lt;P&gt;LOAD * INLINE&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp; 7&lt;/P&gt;&lt;P&gt;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&amp;nbsp; 12&lt;/P&gt;&lt;P&gt;&amp;nbsp; 14&lt;/P&gt;&lt;P&gt;&amp;nbsp; 15&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Purchase:&lt;/P&gt;&lt;P&gt;LOAD * INLINE&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer, purchase, date&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, car, 12/01/2011&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, tires, 12/01/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, motor, 18/04/2013&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, glass, 19/09/2014&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, tires,12/01/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp; 5, parfum, 05/07/2009&lt;/P&gt;&lt;P&gt;&amp;nbsp; 10, water, 30/11/2014&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;MaxYear:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; MAX(YEAR(date)) AS MaxYear&lt;/P&gt;&lt;P&gt;RESIDENT Purchase;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vMaxYear =FLOOR(PEEK('MaxYear',0));&lt;/P&gt;&lt;P&gt;DROP TABLE MaxYear;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PurchaseByYear:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer,&lt;/P&gt;&lt;P&gt;&amp;nbsp; YEAR(date) as year,&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF(YEAR(date) &amp;gt;= $(vMaxYear) -4, 1, 0) AS FlagLastYears,&lt;/P&gt;&lt;P&gt;&amp;nbsp; COUNT(purchase) as TotalPurchase&lt;/P&gt;&lt;P&gt;RESIDENT Purchase&lt;/P&gt;&lt;P&gt;GROUP BY &lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer,&lt;/P&gt;&lt;P&gt;&amp;nbsp; YEAR(date),&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF(YEAR(date) &amp;gt; YEAR(TODAY()-5), 1, 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; ClientFidelity:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer,&lt;/P&gt;&lt;P&gt;&amp;nbsp; SUM(FlagLastYears) AS Fidelity&lt;/P&gt;&lt;P&gt;RESIDENT PurchaseByYear&lt;/P&gt;&lt;P&gt;WHERE TotalPurchase &amp;gt; 0&lt;/P&gt;&lt;P&gt;GROUP BY ID_customer;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LEFT JOIN (Customers) LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer,&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF(Fidelity &amp;gt;= 4, 1, 0) AS Fidelity&lt;/P&gt;&lt;P&gt;RESIDENT ClientFidelity;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DROP TABLE ClientFidelity;&lt;/P&gt;&lt;P&gt;DROP TABLE PurchaseByYear;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Ernesto.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:35:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748107#M664529</guid>
      <dc:creator>consenit</dc:creator>
      <dc:date>2015-01-07T14:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748108#M664530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ernesto,&lt;/P&gt;&lt;P&gt;what I was saying is that if you remove the 2015 date in your previous script, it still gives you a flag value setted to 1 for the customer (I think it's an error). Anyway &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I can study and work using the code you posted, so thank you so much!!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:41:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748108#M664530</guid>
      <dc:creator />
      <dc:date>2015-01-07T14:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748109#M664531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know if you define the last 4 years as current year+previous 3 years or simple as the previous 48 months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example is based on years and should get you started (just change the time interval to whatever you need).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Count({$&amp;lt;Year={"&amp;gt;=$(=Max(Year)-3)&amp;lt;=$(=Max(Year))"}&amp;gt;} DISTINCT Year)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:50:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748109#M664531</guid>
      <dc:creator>martin_dideriks</dc:creator>
      <dc:date>2015-01-07T14:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748110#M664532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Purchase:&lt;/P&gt;&lt;P&gt;LOAD ID_customer, purchase, Date#(date,'DD/MM/YYYY') As date INLINE&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer, purchase, date&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, car, 12/01/2011&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, tires, 12/01/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, motor, 18/04/2013&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, glass, 19/09/2014&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, tires,12/01/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp; 5, parfum, 05/07/2009&lt;/P&gt;&lt;P&gt;&amp;nbsp; 10, water, 30/11/2014&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load ID_customer,If(Sum(DISTINCT Year(Today())-Year(date))=10,'Y','N') As PresentFlag Resident Purchase Group By ID_customer;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 05:51:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748110#M664532</guid>
      <dc:creator>anbu1984</dc:creator>
      <dc:date>2015-01-08T05:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748111#M664533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This can't work as if you have a purchase in 2010, the sum will be 10 and flag will be Y...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 10:16:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748111#M664533</guid>
      <dc:creator />
      <dc:date>2015-01-08T10:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748112#M664534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LET vLastFourYears =&amp;nbsp; (Year(Today())-1) &amp;amp; ';' &amp;amp; (Year(Today())-2) &amp;amp; ';' &amp;amp; (Year(Today())-3) &amp;amp; ';' &amp;amp; (Year(Today())-4);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Purchase:&lt;/P&gt;&lt;P&gt;LOAD ID_customer, purchase, Date#(date,'DD/MM/YYYY') As date INLINE&lt;/P&gt;&lt;P&gt;[&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID_customer, purchase, date&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, car, 12/01/2011&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, car, 12/01/2010&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, tires, 12/01/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, motor, 18/04/2013&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, glass, 19/09/2014&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1, tires,12/01/2012&lt;/P&gt;&lt;P&gt;&amp;nbsp; 5, parfum, 05/07/2009&lt;/P&gt;&lt;P&gt;&amp;nbsp; 10, water, 30/11/2014&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load ID_customer,If(Count(DISTINCT If(Index('$(vLastFourYears)',Year(date)),Year(date)))=4,'Y','N') As PresentFlag Resident Purchase Group By ID_customer;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 11:26:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748112#M664534</guid>
      <dc:creator>anbu1984</dc:creator>
      <dc:date>2015-01-08T11:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748113#M664535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can use this in a list box or as a calculated dimension:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=Aggr(If(Count(DISTINCT Year([purchase date])) &amp;gt;= 4, ID_Customer), ID_Customer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Jonathan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 11:41:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748113#M664535</guid>
      <dc:creator>jonathandienst</dc:creator>
      <dc:date>2015-01-08T11:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748114#M664536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Diego, my expresion didn't worked?&lt;/P&gt;&lt;P&gt;=Aggr(If(Count({&amp;lt;date={'&amp;gt;$(=AddMonths(Today(), -48))'}&amp;gt;} DISTINCT Year(date))=4, ID_customer), ID_customer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want full years you can use:&lt;/P&gt;&lt;P&gt;=Aggr(If(Count({&amp;lt;date={'&amp;gt;$(=YearStart(AddMonths(Today(), -48)))'}&amp;gt;} DISTINCT Year(date))=4, ID_customer), ID_customer)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 12:06:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748114#M664536</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-01-08T12:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748115#M664537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ruben,&lt;/P&gt;&lt;P&gt;i was trying to do it inside the script, I will try also your idea soon!! Thanks!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 12:59:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748115#M664537</guid>
      <dc:creator />
      <dc:date>2015-01-08T12:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748116#M664538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ernesto,&lt;/P&gt;&lt;P&gt;sorry to bother you.. What have I to do if I want also how much a client spent every year in exam? (I'd like to know, if a person bought something every year of the last four year and how much he spent every year) Starting from a table like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;Purchase:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;LOAD * INLINE&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;[&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; ID_customer, purchase, value, date&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 1, car, 10000, 12/01/2011&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 1, tires, 400, 12/01/2012&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 1, motor, 5000, 18/04/2013&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 1, glass, 300, 19/09/2014&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 1, tires, 400, 12/01/2012&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 5, parfum, 80, 05/07/2009&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp; 10, water, 10, 30/11/2014&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;];&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;Thank you in advance for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 16:09:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748116#M664538</guid>
      <dc:creator />
      <dc:date>2015-01-08T16:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Client fidelity check</title>
      <link>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748117#M664539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Customers:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD * INLINE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Purchase:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD * INLINE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer, purchase, value, date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, car, 10000, 12/01/2011&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, tires, 400, 12/01/2012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, motor, 5000, 18/04/2013&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, glass, 300, 19/09/2014&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 1, tires, 400, 12/01/2012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 5, parfum, 80, 05/07/2009&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 10, water, 10, 30/11/2014&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;MaxYear:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; MAX(YEAR(date)) AS MaxYear&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT Purchase;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LET vMaxYear =FLOOR(PEEK('MaxYear',0));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;DROP TABLE MaxYear;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;PurchaseByYear:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; YEAR(date) as year,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF(YEAR(date) &amp;gt;= $(vMaxYear) -4, 1, 0) AS FlagLastYears,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; COUNT(purchase) as TotalPurchase,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SUM(value) as TotalAmount&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT Purchase&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;GROUP BY&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; YEAR(date),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF(YEAR(date) &amp;gt;&amp;nbsp; $(vMaxYear) -4, 1, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;ClientFidelity:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SUM(FlagLastYears) AS Fidelity&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT PurchaseByYear&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;WHERE TotalPurchase &amp;gt; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;GROUP BY ID_customer; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;LEFT JOIN (Customers) LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ID_customer,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF(Fidelity &amp;gt;= 4, 1, 0) AS Fidelity&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RESIDENT ClientFidelity;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;DROP TABLE ClientFidelity;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's basically the same script with an added SUM() of all the values by year and without the last DROP TABLE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Ernesto.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 16:33:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Client-fidelity-check/m-p/748117#M664539</guid>
      <dc:creator>consenit</dc:creator>
      <dc:date>2015-01-08T16:33:58Z</dc:date>
    </item>
  </channel>
</rss>

