<?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: Lookup returning null only in some cases in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Lookup-returning-null-only-in-some-cases/m-p/123861#M8609</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For anyone interested, the problem originated from not &lt;STRONG&gt;specifying the fourth optional parameter&lt;/STRONG&gt; in lookup().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changing it to LookUp('CumulativeValue', RowNumber, PrevRow, 'MonthlyFees') fixed it. Even though it's the same table name that the function is in, apparently I had to specify it, probably because I'm working with joining fields on the same table over and over again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd be curious to know if that is the case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Oct 2018 08:52:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-10-02T08:52:14Z</dc:date>
    <item>
      <title>Lookup returning null only in some cases</title>
      <link>https://community.qlik.com/t5/App-Development/Lookup-returning-null-only-in-some-cases/m-p/123860#M8608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to do some calculated fields with an expression based on the above row in a table. The script is a bit involved, so I'll try to only copy the relevant sections.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For anyone interested in what this formula is/does, &lt;A href="https://www.mrexcel.com/forum/excel-questions/556463-auto-distribution-data-over-months.html"&gt;this thread&lt;/A&gt; is the origin. The aim is to distribute a fee over some months where the fraction of fee in a monthh grows until it reaches a peak towards the end of the period. I have tried to include comments wherever needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem is that the fee for a month (after the first month of course) is based on the difference between cumulative value of current and previous month. I tried using &lt;EM&gt;peek&lt;/EM&gt; but that returns odd results which lead to negative monthly fee(highlighted below, rightmost column). Lookup can't seem to find a match so returns null. Tried previous, above, before, all in the hopes of something working. Alas, no luck. The bolded bits are where I'm trying to show and solve the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attached some sample data and a larger version of the screencap. I really hope the issue is something simple.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-image image-1" height="521" src="https://community.qlik.com/legacyfs/online/214804_pastedImage_2.png" style="width: 1032.58px; height: 521px; float: none;" width="1033" /&gt;&lt;/P&gt;&lt;P&gt;// Loading temp table&lt;/P&gt;&lt;P&gt;T1:&lt;/P&gt;&lt;P&gt;Load ProjectUID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date(FStartDate, 'DD/MM/YYYY') as MinDate, // start of the overall period&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date(FEndDate, 'DD/MM/YYYY') as MaxDate, // end of the overall period&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(IsNull(FProjTotalFee), 0, FProjTotalFee) as FeeValue // total value that needs to be distributed&lt;/P&gt;&lt;P&gt;resident ProjectForecastTbl; // table created previously in code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Creates rows for each month from start to end date&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;MonthlyFees:&lt;/P&gt;&lt;P&gt;load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; date(MonthEnd(AddMonths(MinDate, IterNo()-1, 1)), 'MM/YYYY') as MonthName,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RowNo() as RowNumber&lt;/P&gt;&lt;P&gt;Resident T1 while (month(AddMonths(MinDate, IterNo()-1, 1)) + 12*year(AddMonths(MinDate, IterNo()-1, 1))) &amp;lt;= (month(MaxDate)+12*year(MaxDate));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// add ID to table&lt;/P&gt;&lt;P&gt;Left Join(MonthlyFees)&lt;/P&gt;&lt;P&gt;load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hash128(ProjectUID, MonthName) as FeeID&lt;/P&gt;&lt;P&gt;Resident MonthlyFees;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;drop table T1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// add current month and duration in months&lt;/P&gt;&lt;P&gt;left join(MonthlyFees)&lt;/P&gt;&lt;P&gt;Load FeeID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProjectUID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MonthName,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MinDate,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12*(year(MonthName)-year(MinDate))+(month(MonthName)-month(MinDate)+1)as CurrPeriod, // calculates that current month is nth from period&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12*(year(MaxDate)-year(MinDate))+(Month(MaxDate)-Month(MinDate)+1) as MonthDuration&lt;/P&gt;&lt;P&gt;resident MonthlyFees;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// calculation for T&lt;/P&gt;&lt;P&gt;left join(MonthlyFees)&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (CurrPeriod-2) / (MonthDuration-2) as T // refer to external link for formula if interested&lt;/P&gt;&lt;P&gt;Resident MonthlyFees;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// column for T&lt;/P&gt;&lt;P&gt;left join(MonthlyFees)&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num(if(T&amp;lt;0, 0, if(T&amp;gt;1, 1, 10*pow(T,2)*pow((1-T),2)*($(vA)+$(vB)*T)+pow(T,4)*(5-4*T)))) as CumulativeValue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // vA and vB set previously, refer to external link for formula if interested&lt;/P&gt;&lt;P&gt;resident MonthlyFees&lt;/P&gt;&lt;P&gt;order by RowNumber;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// add fee value&lt;/P&gt;&lt;P&gt;left join(MonthlyFees)&lt;/P&gt;&lt;P&gt;load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(IsNull(&lt;STRONG&gt;LookUp(CumulativeValue, RowNumber, RowNumber-1)&lt;/STRONG&gt;), 'No match', LookUp(CumulativeValue, RowNumber, RowNumber-1)) as deltaCumulativeValue, // this is to illustrate where the Lookup isn't working for some reason&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; money( if ((MonthDuration=1 or MonthDuration=2), if(CurrPeriod=MonthDuration, FeeValue, 0), &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(CurrPeriod=1, CumulativeValue*FeeValue, (CumulativeValue-&lt;STRONG&gt;peek('CumulativeValue')&lt;/STRONG&gt;)*FeeValue)), '£##,###.00', '.', ',')&amp;nbsp; as ForecastMonthlyFee&lt;/P&gt;&lt;P&gt;resident MonthlyFees;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2018 12:10:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Lookup-returning-null-only-in-some-cases/m-p/123860#M8608</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-01T12:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup returning null only in some cases</title>
      <link>https://community.qlik.com/t5/App-Development/Lookup-returning-null-only-in-some-cases/m-p/123861#M8609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For anyone interested, the problem originated from not &lt;STRONG&gt;specifying the fourth optional parameter&lt;/STRONG&gt; in lookup().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changing it to LookUp('CumulativeValue', RowNumber, PrevRow, 'MonthlyFees') fixed it. Even though it's the same table name that the function is in, apparently I had to specify it, probably because I'm working with joining fields on the same table over and over again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd be curious to know if that is the case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Oct 2018 08:52:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Lookup-returning-null-only-in-some-cases/m-p/123861#M8609</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-02T08:52:14Z</dc:date>
    </item>
  </channel>
</rss>

