<?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: Nearest Next Date in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063095#M87189</link>
    <description>&lt;P&gt;Your example doesn't look complete because a payment-table just with dates and without any key to the invoices makes not much sense. But if there is such key the payment-table might be aggregated to the max date - so it might be look like:&lt;/P&gt;
&lt;P&gt;t: load InvoiceID, InvoiceDate from Invoices;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; left join(t) load InvoiceID, date(max(PaymentDate)) as PaymentDateMax from Payments&lt;BR /&gt;&amp;nbsp; &amp;nbsp; group by InvoiceID;&lt;/P&gt;
&lt;P&gt;Another approach might be just to rank the payment-dates, for example:&lt;/P&gt;
&lt;P&gt;t: load InvoiceID, PaymentDate, &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(InvoiceID = previous(InvoiceID), peek('Rank') + 1, 1) as Rank&lt;BR /&gt;&amp;nbsp; &amp;nbsp; resident Invoices &lt;STRONG&gt;order by InvoiceID, PaymentDate desc&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;and then Rank could be used as dimension, selection or set analysis condition.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2023 13:43:39 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2023-04-21T13:43:39Z</dc:date>
    <item>
      <title>Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2062946#M87176</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;Looking for the Script to pick nearest next Date from the list of dates. I have below example to show. in MM/DD/YYYY&lt;/P&gt;
&lt;P&gt;Table A: Invoices with Due Dates&lt;/P&gt;
&lt;TABLE style="width: 140px;" width="140"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Invoice&lt;/TD&gt;
&lt;TD width="76"&gt;Due date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;3/31/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5678&lt;/TD&gt;
&lt;TD&gt;1/30/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;9012&lt;/TD&gt;
&lt;TD&gt;12/20/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;12/31/2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table B : Payment Dates&lt;/P&gt;
&lt;TABLE width="76"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="76"&gt;Payment Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1/31/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3/30/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/5/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12/30/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1/2/2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each invoices from Table A, I would like to pick next Nearest Payment date from Table B.&lt;/P&gt;
&lt;P&gt;Result should appear as below;&lt;/P&gt;
&lt;TABLE width="291"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Invoice&lt;/TD&gt;
&lt;TD width="76"&gt;Due date&lt;/TD&gt;
&lt;TD width="151"&gt;Next Nearest Pmnt Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234&lt;/TD&gt;
&lt;TD&gt;3/31/2022&lt;/TD&gt;
&lt;TD&gt;4/5/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5678&lt;/TD&gt;
&lt;TD&gt;1/30/2022&lt;/TD&gt;
&lt;TD&gt;1/31/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;9012&lt;/TD&gt;
&lt;TD&gt;12/20/2022&lt;/TD&gt;
&lt;TD&gt;12/30/2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3456&lt;/TD&gt;
&lt;TD&gt;12/31/2022&lt;/TD&gt;
&lt;TD&gt;1/2/2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to do this in Script ?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 09:16:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2062946#M87176</guid>
      <dc:creator>RC_121985</dc:creator>
      <dc:date>2023-04-21T09:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063002#M87180</link>
      <description>&lt;P&gt;Hi, not so elegant solution, but you can try something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TableA:
LOAD * inline [
Invoice, Due date
1234, 2022-03-31
5678, 2022-01-30
9012, 2022-12-20
3456, 2022-12-31];

TableB:
LOAD * inline [
Payment Date
2022-01-31
2022-03-30
2022-04-05
2022-12-30
2023-01-02];

NoConcatenate
main_temp:
LOAD 
Invoice,
[Due date]
RESIDENT TableA;

JOIN LOAD
[Payment Date] as [Due date],
[Payment Date]
RESIDENT TableB;

DROP TABLES TableA, TableB;

NoConcatenate
main_temp2:
LOAD
Invoice,
[Due date],
if(isnull([Payment Date]), peek([Payment Date]), [Payment Date]) as [Payment Date]
RESIDENT main_temp
ORDER BY [Due date] DESC; //sorting backwards to peek

NoConcatenate
Main:
LOAD 
Invoice,
[Due date],
[Payment Date] as [Next Nearest Pmnt Date]
RESIDENT main_temp2
WHERE not isnull(Invoice)
ORDER BY [Due date] ASC; //get back sorting

DROP TABLES main_temp, main_temp2;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Basically, you make a list of all possible dates, sorting them descending and with peek() (or previous()) find nearest date for invoice.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 11:16:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063002#M87180</guid>
      <dc:creator>justISO</dc:creator>
      <dc:date>2023-04-21T11:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063020#M87186</link>
      <description>&lt;P&gt;Hi JustISO,&lt;/P&gt;
&lt;P&gt;Good Solution. If I do not find any quick fix then, it is only the solution I believe.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 11:58:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063020#M87186</guid>
      <dc:creator>RC_121985</dc:creator>
      <dc:date>2023-04-21T11:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063095#M87189</link>
      <description>&lt;P&gt;Your example doesn't look complete because a payment-table just with dates and without any key to the invoices makes not much sense. But if there is such key the payment-table might be aggregated to the max date - so it might be look like:&lt;/P&gt;
&lt;P&gt;t: load InvoiceID, InvoiceDate from Invoices;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; left join(t) load InvoiceID, date(max(PaymentDate)) as PaymentDateMax from Payments&lt;BR /&gt;&amp;nbsp; &amp;nbsp; group by InvoiceID;&lt;/P&gt;
&lt;P&gt;Another approach might be just to rank the payment-dates, for example:&lt;/P&gt;
&lt;P&gt;t: load InvoiceID, PaymentDate, &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(InvoiceID = previous(InvoiceID), peek('Rank') + 1, 1) as Rank&lt;BR /&gt;&amp;nbsp; &amp;nbsp; resident Invoices &lt;STRONG&gt;order by InvoiceID, PaymentDate desc&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;and then Rank could be used as dimension, selection or set analysis condition.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 13:43:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063095#M87189</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-04-21T13:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063111#M87191</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/83295"&gt;@RC_121985&lt;/a&gt;&amp;nbsp; try below as well&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;TableA:
LOAD * inline [
Invoice, Due date
1234, 2022-03-31
5678, 2022-01-30
9012, 2022-12-20
3456, 2022-12-31];

TableB:
LOAD * inline [
Payment Date
2022-01-31
2022-03-30
2022-04-05
2022-12-30
2023-01-02];

Dates:
Load date(FieldValue('Due date',RecNo())) as [Due date]
AutoGenerate FieldValueCount('Due date');

join(Dates)
Load date(FieldValue('Payment Date',RecNo())) as [Payment Date]
AutoGenerate FieldValueCount('Payment Date');

Left Join(TableA)
Load [Due date],
     date(min([Payment Date])) as [Next Nearest Payment Date]
Resident Dates
where [Payment Date]&amp;gt;[Due date]
Group by [Due date];

Drop Table Dates;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:03:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063111#M87191</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2023-04-21T14:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063126#M87194</link>
      <description>&lt;P&gt;No There is no key. Because It is just the dates of the Payments executed.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:15:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063126#M87194</guid>
      <dc:creator>RC_121985</dc:creator>
      <dc:date>2023-04-21T14:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063129#M87195</link>
      <description>&lt;P&gt;I don't believe that there is no relation between this information. It would lead to a single max. date from the payments against all invoices ...&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:20:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063129#M87195</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-04-21T14:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063140#M87197</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the script. In fact Result is multiplied no of time the payment dates. I don't think it is working.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:39:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063140#M87197</guid>
      <dc:creator>RC_121985</dc:creator>
      <dc:date>2023-04-21T14:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063147#M87201</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/83295"&gt;@RC_121985&lt;/a&gt;&amp;nbsp; not sure how it is multiplying as you are joining single next payment date with due date. make sure that you are joining with tableA on Due Date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:49:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063147#M87201</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2023-04-21T14:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063228#M87206</link>
      <description>&lt;P&gt;another solution might be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;tabInvoices:
LOAD * Inline [
    Invoice, Due date
    1234, 3/31/2022
    5678, 1/30/2022
    9012, 12/20/2022
    3456, 12/31/2022
];

tabPayments:
LOAD * Inline [
    Payment Date
    1/31/2022
    3/30/2022
    4/5/2022
    12/30/2022
    1/2/2023
];

Join (tabInvoices)
IntervalMatch ([Due date])
LOAD Distinct
     Alt(Previous([Payment Date]),0)	as PrevPaymentDate,
     [Payment Date]						as NextNearestPmntDate
Resident tabPayments
Order By [Payment Date];&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case there is a CustomerID to tie invoices and payments to, you could use the extended IntervalMatch prefix as well:&lt;BR /&gt;&lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/IntervalMatch.htm" target="_blank"&gt;https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptPrefixes/IntervalMatch.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:45:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063228#M87206</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2023-04-21T17:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063322#M87217</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp; right If I drop the TableB it's Good.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2023 15:49:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063322#M87217</guid>
      <dc:creator>RC_121985</dc:creator>
      <dc:date>2023-04-22T15:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Next Date</title>
      <link>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063575#M87232</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/675"&gt;@MarcoWedel&lt;/a&gt;&amp;nbsp;Some how the result is not correct where the same due date is repeating. or more than 2 due days falling on Payments dates are getting 2 different Nearestduedate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 10:05:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Nearest-Next-Date/m-p/2063575#M87232</guid>
      <dc:creator>RC_121985</dc:creator>
      <dc:date>2023-04-24T10:05:25Z</dc:date>
    </item>
  </channel>
</rss>

