<?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 Adding a variable to a join based on Max Date in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Adding-a-variable-to-a-join-based-on-Max-Date/m-p/474513#M1145257</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;&lt;/P&gt;&lt;P&gt;I have customers, which are booked for appointments. I use the following script to create a left join to see, when they're booked for their next appointment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left Join ([Appoint Temp])&lt;/P&gt;&lt;P&gt;LOAD Contact, &lt;/P&gt;&lt;P&gt;Date(Max(Left(EventDate,5))) as [NEXTTEVENT],&lt;/P&gt;&lt;P&gt;From [..\Data\QVD\xxx.qvd] (qvd) &lt;/P&gt;&lt;P&gt;Where Date(Left(EventDate,5))&amp;gt;Today() &lt;/P&gt;&lt;P&gt;Group By Contact;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That works well for me, and I get the result I'm looking for. My problem arises when I want to add a variable e.g. I want to see what kind of appointment type they've booked. The variable is called "Appointment Type" and I thought I could just add it to the script, but that doesn't work for me (I get an error saying invalid expression):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD Contact, &lt;/P&gt;&lt;P&gt;Date(Max(Left(EventDate,5))) as [NEXTTEVENT],&lt;/P&gt;&lt;P&gt;AppointmentType as [NEXTAPPTTYPE] &lt;/P&gt;&lt;P&gt;From [..\Data\QVD\xxx.qvd] (qvd) &lt;/P&gt;&lt;P&gt;Where Date(Left(EventDate,5))&amp;gt;Today() &lt;/P&gt;&lt;P&gt;Group By Contact;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will I need to do several loads?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking forward to hear from you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Aug 2013 18:20:44 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-08-07T18:20:44Z</dc:date>
    <item>
      <title>Adding a variable to a join based on Max Date</title>
      <link>https://community.qlik.com/t5/QlikView/Adding-a-variable-to-a-join-based-on-Max-Date/m-p/474513#M1145257</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;&lt;/P&gt;&lt;P&gt;I have customers, which are booked for appointments. I use the following script to create a left join to see, when they're booked for their next appointment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left Join ([Appoint Temp])&lt;/P&gt;&lt;P&gt;LOAD Contact, &lt;/P&gt;&lt;P&gt;Date(Max(Left(EventDate,5))) as [NEXTTEVENT],&lt;/P&gt;&lt;P&gt;From [..\Data\QVD\xxx.qvd] (qvd) &lt;/P&gt;&lt;P&gt;Where Date(Left(EventDate,5))&amp;gt;Today() &lt;/P&gt;&lt;P&gt;Group By Contact;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That works well for me, and I get the result I'm looking for. My problem arises when I want to add a variable e.g. I want to see what kind of appointment type they've booked. The variable is called "Appointment Type" and I thought I could just add it to the script, but that doesn't work for me (I get an error saying invalid expression):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD Contact, &lt;/P&gt;&lt;P&gt;Date(Max(Left(EventDate,5))) as [NEXTTEVENT],&lt;/P&gt;&lt;P&gt;AppointmentType as [NEXTAPPTTYPE] &lt;/P&gt;&lt;P&gt;From [..\Data\QVD\xxx.qvd] (qvd) &lt;/P&gt;&lt;P&gt;Where Date(Left(EventDate,5))&amp;gt;Today() &lt;/P&gt;&lt;P&gt;Group By Contact;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will I need to do several loads?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking forward to hear from you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 18:20:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Adding-a-variable-to-a-join-based-on-Max-Date/m-p/474513#M1145257</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-08-07T18:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a variable to a join based on Max Date</title>
      <link>https://community.qlik.com/t5/QlikView/Adding-a-variable-to-a-join-based-on-Max-Date/m-p/474514#M1145260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorted it out with help from this discussion: &lt;A _jive_internal="true" href="https://community.qlik.com/message/318967#318967"&gt;http://community.qlik.com/message/318967#318967&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Trick was to use FirstSortedValue &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD Contact, &lt;/P&gt;&lt;P&gt;Date(Max(Left(EventDate,5))) as [NEXTTEVENT],&lt;/P&gt;&lt;P&gt;FirstSortedValue(AppointmentType, EventDate) as [NEXTAPPTTYPE] &lt;/P&gt;&lt;P&gt;From [..\Data\QVD\xxx.qvd] (qvd) &lt;/P&gt;&lt;P&gt;Where Date(Left(EventDate,5))&amp;gt;Today() &lt;/P&gt;&lt;P&gt;Group By Contact;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 18:54:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Adding-a-variable-to-a-join-based-on-Max-Date/m-p/474514#M1145260</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-08-07T18:54:08Z</dc:date>
    </item>
  </channel>
</rss>

