<?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 How to use applymap and getting the higest date? in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744823#M57134</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a simple exchange rate table with exchange rates per Year - Month:&lt;BR /&gt;Exchangerate:&lt;BR /&gt;ExchangeRateDate, ExchangeRate&lt;BR /&gt;2020-01, 0.88&lt;BR /&gt;2020-02, 0.89&lt;/P&gt;&lt;P&gt;I have a mapping load function like this:&lt;/P&gt;&lt;P&gt;Map_Currency_Rate_PL:&lt;BR /&gt;Mapping Load&lt;BR /&gt;DATE(MonthStart(ExchangeRateDate),'YYYY-MM') AS CurrencyKey,&lt;BR /&gt;ExchangeRatePL&lt;BR /&gt;RESIDENT Exchangerate;&lt;/P&gt;&lt;P&gt;I also have a facts table with amounts, like&lt;BR /&gt;LineNo, transactiondate, amount&lt;BR /&gt;1, 2020-01-01, 100&lt;BR /&gt;2, 2020-03-30, 200&lt;/P&gt;&lt;P&gt;I the load of this fact table I use function:&lt;BR /&gt;APPLYMAP('Map_Currency_Rate_PL', DATE(MonthStart(transactiondate),'YYYY-MM'))&lt;/P&gt;&lt;P&gt;This Applymap function works fine for line 1, as there is an exchange rate for January 2020.&lt;BR /&gt;But for line 2 it returns nothing as it can not find an exchange rate in March 2020.&lt;/P&gt;&lt;P&gt;In this scenario I want to get the higest date from the exchange rate table which is February 2020 in case the date is not available.&lt;BR /&gt;How do I do that?&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 18:05:45 GMT</pubDate>
    <dc:creator>heij1421</dc:creator>
    <dc:date>2024-11-16T18:05:45Z</dc:date>
    <item>
      <title>How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744823#M57134</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a simple exchange rate table with exchange rates per Year - Month:&lt;BR /&gt;Exchangerate:&lt;BR /&gt;ExchangeRateDate, ExchangeRate&lt;BR /&gt;2020-01, 0.88&lt;BR /&gt;2020-02, 0.89&lt;/P&gt;&lt;P&gt;I have a mapping load function like this:&lt;/P&gt;&lt;P&gt;Map_Currency_Rate_PL:&lt;BR /&gt;Mapping Load&lt;BR /&gt;DATE(MonthStart(ExchangeRateDate),'YYYY-MM') AS CurrencyKey,&lt;BR /&gt;ExchangeRatePL&lt;BR /&gt;RESIDENT Exchangerate;&lt;/P&gt;&lt;P&gt;I also have a facts table with amounts, like&lt;BR /&gt;LineNo, transactiondate, amount&lt;BR /&gt;1, 2020-01-01, 100&lt;BR /&gt;2, 2020-03-30, 200&lt;/P&gt;&lt;P&gt;I the load of this fact table I use function:&lt;BR /&gt;APPLYMAP('Map_Currency_Rate_PL', DATE(MonthStart(transactiondate),'YYYY-MM'))&lt;/P&gt;&lt;P&gt;This Applymap function works fine for line 1, as there is an exchange rate for January 2020.&lt;BR /&gt;But for line 2 it returns nothing as it can not find an exchange rate in March 2020.&lt;/P&gt;&lt;P&gt;In this scenario I want to get the higest date from the exchange rate table which is February 2020 in case the date is not available.&lt;BR /&gt;How do I do that?&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 18:05:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744823#M57134</guid>
      <dc:creator>heij1421</dc:creator>
      <dc:date>2024-11-16T18:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744891#M57146</link>
      <description>&lt;P&gt;I guess Applymap wont work in your case. what you could do is to join the 2 Tables by Date and then using peek function to get the wanted value.&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Fact:
Load *, left(transactiondate,7) as ExchangeRateDate;
Load * Inline [
LineNo, transactiondate, amount
1, 2020-01-01, 100
2, 2020-03-30, 200
];

join

Load * Inline [
ExchangeRateDate, ExchangeRate
2020-01, 0.88
2020-02, 0.89
];

NoConcatenate

Load *,if(isnull(ExchangeRate),peek(ExchangeRate),ExchangeRate) as ExchangeRate_New 
Resident Fact Order by ExchangeRateDate;
drop table Fact;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Unbenannt.png" style="width: 200px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/40756i522CC89E05EC495E/image-size/small?v=v2&amp;amp;px=200" role="button" title="Unbenannt.png" alt="Unbenannt.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 18:25:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744891#M57146</guid>
      <dc:creator>Frank_Hartmann</dc:creator>
      <dc:date>2020-09-17T18:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744914#M57150</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/44113"&gt;@heij1421&lt;/a&gt;&amp;nbsp; another approach with applymap itself. Assuming&amp;nbsp;transactiondate has a proper date format.&amp;nbsp; If not then first convert it to date format using Date# function&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Exchangerate:
mapping LOAD date(date#(ExchangeRateDate,'YYYY-MM'),'YYYY-MM') as ExchangeRateDate,
             ExchangeRate
FROM ExchangeRateTable;

Exchangerate_latest:
load FirstSortedValue(ExchangeRate,-ExchangeRateDate) as Latest_Exchange_Rate;
LOAD date(date#(ExchangeRateDate,'YYYY-MM'),'YYYY-MM') as ExchangeRateDate, 
     ExchangeRate
FROM ExchangeRateTable;

let vLatest_Exchange_Rate = Peek('Latest_Exchange_Rate',0,'Exchangerate_latest');

DROP Table Exchangerate_latest;

Fact:
Load LineNo, 
     transactiondate, 
     amount,
      ApplyMap('Exchangerate',date(transactiondate,'YYYY-MM'),$(vLatest_Exchange_Rate)) as FROM transaction table;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 22:13:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1744914#M57150</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2020-09-17T22:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747611#M57464</link>
      <description>&lt;P&gt;Thanks for the replies both&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/29675"&gt;@Frank_Hartmann&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp;. Both solutions are OK with the given data, but I have to admin my request was not complete.&amp;nbsp; Sorry for that.&amp;nbsp; It should not give the exchange rate for the higest date, but the exchange rate for the higest date before the transaction date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me explane:&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use this script from Frank Hartman:&lt;/P&gt;&lt;P&gt;Fact:&lt;BR /&gt;Load *, left(transactiondate,7) as ExchangeRateDate;&lt;BR /&gt;Load * Inline [&lt;BR /&gt;LineNo, transactiondate, amount&lt;BR /&gt;1, 2020-01-01, 100&lt;BR /&gt;2, 2020-02-12, 100&lt;BR /&gt;3, 2020-02-13, 100&lt;BR /&gt;4, 2020-04-01, 100&lt;BR /&gt;5, 2020-05-10, 100&lt;BR /&gt;6, 2020-06-01, 100&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;join&lt;/P&gt;&lt;P&gt;[ExchangeRatetable]:&lt;BR /&gt;Load * Inline [&lt;BR /&gt;ExchangeRateDate, ExchangeRate&lt;BR /&gt;2020-01, 0.81&lt;BR /&gt;2020-02, 0.82&lt;BR /&gt;2020-03, 0.83&lt;BR /&gt;2020-05, 0.85&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;/P&gt;&lt;P&gt;Load LineNo,&lt;BR /&gt;transactiondate,&lt;BR /&gt;amount ,&lt;BR /&gt;if(isnull(ExchangeRate),peek(ExchangeRate),ExchangeRate) as ExchangeRate_New&lt;BR /&gt;Resident Fact Order by ExchangeRateDate;&lt;BR /&gt;drop table Fact;&lt;/P&gt;&lt;P&gt;exit Script;&lt;/P&gt;&lt;P&gt;It returns&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="heij1421_1-1601283824405.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/41304i885B3F2166F1238A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="heij1421_1-1601283824405.png" alt="heij1421_1-1601283824405.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line No 1, 2, 3 and 5 are OK.&lt;/P&gt;&lt;P&gt;Line 4 should return an exchange rate of 0,83 as in April the last known exchange rate before April was from March&lt;BR /&gt;Line 6 should return an exchange rate of 0,85 as in June the last know exchange rate was from May.&lt;BR /&gt;So if there is no exchange rate available for the transaction date it should return the last exchange rate before that year-month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:04:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747611#M57464</guid>
      <dc:creator>heij1421</dc:creator>
      <dc:date>2020-09-28T09:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747627#M57465</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/44113"&gt;@heij1421&lt;/a&gt;&amp;nbsp; try below. Assuming that your transaction date is in proper date format and not text. Also format of the exchange date rate is YYYY-MM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Exchange_Rate_Map:
mapping load monthstart((date#(ExchangeRateDate,'YYYY-MM'))) as ExchangeRateDate,
             ExchangeRate;
Load * Inline [
ExchangeRateDate, ExchangeRate
2020-01, 0.81
2020-02, 0.82
2020-03, 0.83
2020-05, 0.85
];

Fact:
Load *,applymap('Exchange_Rate_Map',monthstart(transactiondate),null()) as ExchangeRate
Inline [
LineNo, transactiondate, amount
1, 2020-01-01, 100
2, 2020-02-12, 100
3, 2020-02-13, 100
4, 2020-04-01, 100
5, 2020-05-10, 100
6, 2020-06-01, 100
];

Final:
NoConcatenate
Load LineNo, 
     transactiondate, 
     amount,
    if(IsNull(ExchangeRate),Peek(ExchangeRate),ExchangeRate) as ExchangeRate
Resident Fact
Order by transactiondate;

Drop Table Fact;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2020-09-28 105003.png" style="width: 724px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/41310i55029E599DDEE672/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2020-09-28 105003.png" alt="Screenshot 2020-09-28 105003.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:51:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747627#M57465</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2020-09-28T09:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747636#M57468</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp;. In your solution line 4 returns 0.82 where it should return 0.83&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:11:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747636#M57468</guid>
      <dc:creator>heij1421</dc:creator>
      <dc:date>2020-09-28T10:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use applymap and getting the higest date?</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747649#M57470</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/44113"&gt;@heij1421&lt;/a&gt;&amp;nbsp; try below&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Fact:
Load *, 
monthstart(transactiondate) as ExchangeRateDate,
1 as Flag
Inline [
LineNo, transactiondate, amount
1, 2020-01-01, 100
2, 2020-02-12, 100
3, 2020-02-13, 100
4, 2020-04-01, 100
5, 2020-05-10, 100
6, 2020-06-01, 100
];

Join(Fact)
load monthstart(date(date#(ExchangeRateDate,'YYYY-MM'))) as ExchangeRateDate,
             ExchangeRate;
Load * Inline [
ExchangeRateDate, ExchangeRate
2020-01, 0.81
2020-02, 0.82
2020-03, 0.83
2020-05, 0.85
];

T1:
NoConcatenate
Load LineNo, 
     transactiondate, 
     amount,
     Flag,
    if(IsNull(ExchangeRate),Peek(ExchangeRate),ExchangeRate) as ExchangeRate
Resident Fact
Order by ExchangeRateDate,transactiondate;
     

DROP Table Fact;

Final:
NoConcatenate
Load LineNo, 
     transactiondate, 
     amount,
     Flag,
     ExchangeRate
Resident T1
Where Flag=1;

DROP Table T1;&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:33:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-use-applymap-and-getting-the-higest-date/m-p/1747649#M57470</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2020-09-28T10:33:48Z</dc:date>
    </item>
  </channel>
</rss>

