<?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: Select nearest date in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376990#M140548</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I managed to get the desired result :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I created a new variable "&lt;CODE class="jive-code"&gt;choosenDate&lt;/CODE&gt;" equal to &lt;SPAN style="color: #636363; font-family: Arial; font-size: 12px; background-color: #eef4f9;"&gt;Date#(year&amp;amp;month(mois,00)&amp;amp;01, 'YYYYMMDD')&lt;/SPAN&gt; and used it in the expression as follow&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=FirstSortedValue(distinct date, (fabs(date- &lt;CODE class="jive-code"&gt;choosenDate&lt;/CODE&gt;)))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Aug 2012 09:43:16 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-08-13T09:43:16Z</dc:date>
    <item>
      <title>Select nearest date</title>
      <link>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376987#M140545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all, here is my problem :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a record of product price associed with the date :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; price&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to do is to find the product price at some date, and if there isn't a record with this date select the nearest one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is the expression I tried to use :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13446056417681149" jivemacro_uid="_13446056417681149"&gt;&lt;P&gt;date(FirstSortedValue(distinct date, fabs(date - choosenDate)))&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I order the record by their distance with the choosen date and only take the first one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea why it doesn't work ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 13:36:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376987#M140545</guid>
      <dc:creator />
      <dc:date>2012-08-10T13:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Select nearest date</title>
      <link>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376988#M140546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is choosenDate? A field? And if so, how are these fields connected?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;EM&gt;=Date(FirstSortedValue(date, aggr(fabs(date-choosenDate),date)))&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 13:48:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376988#M140546</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-08-10T13:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select nearest date</title>
      <link>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376989#M140547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In reality choosenDate is computed from two variables, year and month :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Date#(year&amp;amp;month(mois,00)&amp;amp;01, 'YYYYMMDD')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Aug 2012 14:31:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376989#M140547</guid>
      <dc:creator />
      <dc:date>2012-08-10T14:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select nearest date</title>
      <link>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376990#M140548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I managed to get the desired result :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I created a new variable "&lt;CODE class="jive-code"&gt;choosenDate&lt;/CODE&gt;" equal to &lt;SPAN style="color: #636363; font-family: Arial; font-size: 12px; background-color: #eef4f9;"&gt;Date#(year&amp;amp;month(mois,00)&amp;amp;01, 'YYYYMMDD')&lt;/SPAN&gt; and used it in the expression as follow&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=FirstSortedValue(distinct date, (fabs(date- &lt;CODE class="jive-code"&gt;choosenDate&lt;/CODE&gt;)))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 09:43:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Select-nearest-date/m-p/376990#M140548</guid>
      <dc:creator />
      <dc:date>2012-08-13T09:43:16Z</dc:date>
    </item>
  </channel>
</rss>

