<?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 Getting the Previous Contract’s Date and Amount in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Getting-the-Previous-Contract-s-Date-and-Amount/m-p/2538652#M108977</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I’m trying to figure out how to pull the previous contract’s details from a master table. Here’s the setup:&lt;/P&gt;&lt;P&gt;CustomerID,ContractID,TransDate, Disbursed Amount&lt;/P&gt;&lt;P&gt;Every time a contract is completed, a new ContractID is created. What I need is:&lt;/P&gt;&lt;P&gt;For any current contract, get the date and amount of the previous contract.&lt;/P&gt;&lt;P&gt;If a customer has multiple past contracts, I only want the most recent one before the current contract.&lt;/P&gt;&lt;P&gt;I’d love to see how you’d approach it, either in the script or using chart expressions. Any tips, examples, or best practices would be great.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 09 Dec 2025 14:45:54 GMT</pubDate>
    <dc:creator>LoKi_asterix</dc:creator>
    <dc:date>2025-12-09T14:45:54Z</dc:date>
    <item>
      <title>Getting the Previous Contract’s Date and Amount</title>
      <link>https://community.qlik.com/t5/App-Development/Getting-the-Previous-Contract-s-Date-and-Amount/m-p/2538652#M108977</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I’m trying to figure out how to pull the previous contract’s details from a master table. Here’s the setup:&lt;/P&gt;&lt;P&gt;CustomerID,ContractID,TransDate, Disbursed Amount&lt;/P&gt;&lt;P&gt;Every time a contract is completed, a new ContractID is created. What I need is:&lt;/P&gt;&lt;P&gt;For any current contract, get the date and amount of the previous contract.&lt;/P&gt;&lt;P&gt;If a customer has multiple past contracts, I only want the most recent one before the current contract.&lt;/P&gt;&lt;P&gt;I’d love to see how you’d approach it, either in the script or using chart expressions. Any tips, examples, or best practices would be great.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2025 14:45:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Getting-the-Previous-Contract-s-Date-and-Amount/m-p/2538652#M108977</guid>
      <dc:creator>LoKi_asterix</dc:creator>
      <dc:date>2025-12-09T14:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Previous Contract’s Date and Amount</title>
      <link>https://community.qlik.com/t5/App-Development/Getting-the-Previous-Contract-s-Date-and-Amount/m-p/2538815#M108990</link>
      <description>&lt;P&gt;Hi loki,&lt;/P&gt;&lt;P&gt;I was able get the correct O/p with the followig script, might not be most optimal solution but worked for the sample data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;//___________________________________________________Script________________________//&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;BR /&gt;Contract:&lt;BR /&gt;Load&lt;BR /&gt;CustomerID,&lt;BR /&gt;ContractID,&lt;BR /&gt;Date(Date#(TransDate,'DD-MM-YYYY'),'DD/MM/YYYY') as TransDate,&lt;BR /&gt;sum("Disbursed Amount") as "Disbursed Amount"&lt;BR /&gt;group by CustomerID,ContractID,TransDate;&lt;BR /&gt;Load * INLINE [&lt;BR /&gt;CustomerID, ContractID, TransDate, Disbursed Amount&lt;BR /&gt;Apple,112,01-02-2024,2000&lt;BR /&gt;Apple,113,01-01-2025,4000&lt;BR /&gt;Apple,114,01-06-2025,100000&lt;BR /&gt;Apple,100,01-01-2023,61000&lt;BR /&gt;Apple,116,01-11-2025,75000&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;left Join(Contract)&lt;BR /&gt;Temp:&lt;BR /&gt;Load&lt;BR /&gt;CustomerID,&lt;BR /&gt;max(TransDate) as Flag&lt;BR /&gt;Resident Contract group by CustomerID;&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;BR /&gt;Final:&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;Resident Contract where Flag=TransDate;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left Join(Final)&lt;BR /&gt;Load&lt;BR /&gt;CustomerID,&lt;BR /&gt;FirstSortedValue(ContractID,-TransDate,2) as PreviousContract&lt;BR /&gt;Resident Contract group by CustomerID;&lt;BR /&gt;// Drop Table Contract;&lt;BR /&gt;&lt;BR /&gt;Left Join(Final)&lt;BR /&gt;Load&lt;BR /&gt;ContractID as PreviousContract,&lt;BR /&gt;TransDate as PreviousDate,&lt;BR /&gt;"Disbursed Amount" as PreviousAmount&lt;BR /&gt;Resident Contract;&lt;/P&gt;&lt;P&gt;Drop Table Contract;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Exit Script;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 11:23:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Getting-the-Previous-Contract-s-Date-and-Amount/m-p/2538815#M108990</guid>
      <dc:creator>Rushi21</dc:creator>
      <dc:date>2025-12-10T11:23:03Z</dc:date>
    </item>
  </channel>
</rss>

