<?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 select the first expiring date (min function for date) in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1766030#M59257</link>
    <description>&lt;P&gt;Dears,&lt;/P&gt;&lt;P&gt;I need to select, from an excel file, the first expiring date for a material code.&lt;/P&gt;&lt;P&gt;As example:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Material code&lt;/TD&gt;&lt;TD&gt;Date field&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;01.05.2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;12.11.2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;18.06.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6789&lt;/TD&gt;&lt;TD&gt;31.12.9999&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6789&lt;/TD&gt;&lt;TD&gt;14.09.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3210&lt;/TD&gt;&lt;TD&gt;31.12.9999&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result table:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Material code&lt;/TD&gt;&lt;TD&gt;Date field&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;12.11.2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6789&lt;/TD&gt;&lt;TD&gt;14.09.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3210&lt;/TD&gt;&lt;TD&gt;31.12.9999&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here I have three problems:&lt;/P&gt;&lt;P&gt;1) Date value format with dots "." looks to not be recognized as date, therefore if I try then to select the minimum value (first expiring date) I get -- as result in the table of the sheet.&lt;/P&gt;&lt;P&gt;2) Date&amp;nbsp;31.12.9999 is frequently used by our SAP user to define a not expiring material code as it looks as not a real date, I need to show it, if it is the unique date for a specific material code&lt;/P&gt;&lt;P&gt;3) have the min function working with dates&lt;/P&gt;&lt;P&gt;I tried several statements in the script from showing the value as it is, without any conversion, just aggregating data with min function to applying conversions to data and replacing "." with "/" without any success:&lt;/P&gt;&lt;P&gt;min("Date field")&lt;/P&gt;&lt;P&gt;date#(alt("Date field",'DD.MM.YYYY','dd-mmm-yyyy'))&amp;nbsp;&lt;/P&gt;&lt;P&gt;min(Date#(Date("Date field")))&lt;/P&gt;&lt;P&gt;Date(Date#(min(num(right("Date field",4)&amp;amp;mid("Date field",4,2)&amp;amp;left("Date field",2)))))&lt;/P&gt;&lt;P&gt;Date(min("Date field"))&lt;/P&gt;&lt;P&gt;min(Date(Date#(replace("Valid to",'.','/'))))&lt;/P&gt;&lt;P&gt;The results I get is usually -- or&amp;nbsp; 28-Aug-275447 which I honestly don't know where it come from.&lt;/P&gt;&lt;P&gt;Do you have any suggestion?&lt;/P&gt;&lt;P&gt;The load I use is pretty simple:&lt;/P&gt;&lt;P&gt;LOAD&lt;BR /&gt;Material,&lt;BR /&gt;Min(num(right("Date field",4)&amp;amp;mid("Date field",4,2)&amp;amp;left("Date field",2))) as "Date field"&lt;/P&gt;&lt;P&gt;FROM [lib://NPI Data Readiness (eu_anori2)/PHARM REPORTING/SAP/ERP2 YI031.xls]&lt;BR /&gt;(txt, unicode, embedded labels, delimiter is '\t', msq, header is 3 lines)&lt;/P&gt;&lt;P&gt;group by Material;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Dec 2021 21:08:46 GMT</pubDate>
    <dc:creator>aryx</dc:creator>
    <dc:date>2021-12-20T21:08:46Z</dc:date>
    <item>
      <title>How to select the first expiring date (min function for date)</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1766030#M59257</link>
      <description>&lt;P&gt;Dears,&lt;/P&gt;&lt;P&gt;I need to select, from an excel file, the first expiring date for a material code.&lt;/P&gt;&lt;P&gt;As example:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Material code&lt;/TD&gt;&lt;TD&gt;Date field&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;01.05.2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;12.11.2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;18.06.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6789&lt;/TD&gt;&lt;TD&gt;31.12.9999&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6789&lt;/TD&gt;&lt;TD&gt;14.09.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3210&lt;/TD&gt;&lt;TD&gt;31.12.9999&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result table:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Material code&lt;/TD&gt;&lt;TD&gt;Date field&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;12.11.2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6789&lt;/TD&gt;&lt;TD&gt;14.09.2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3210&lt;/TD&gt;&lt;TD&gt;31.12.9999&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here I have three problems:&lt;/P&gt;&lt;P&gt;1) Date value format with dots "." looks to not be recognized as date, therefore if I try then to select the minimum value (first expiring date) I get -- as result in the table of the sheet.&lt;/P&gt;&lt;P&gt;2) Date&amp;nbsp;31.12.9999 is frequently used by our SAP user to define a not expiring material code as it looks as not a real date, I need to show it, if it is the unique date for a specific material code&lt;/P&gt;&lt;P&gt;3) have the min function working with dates&lt;/P&gt;&lt;P&gt;I tried several statements in the script from showing the value as it is, without any conversion, just aggregating data with min function to applying conversions to data and replacing "." with "/" without any success:&lt;/P&gt;&lt;P&gt;min("Date field")&lt;/P&gt;&lt;P&gt;date#(alt("Date field",'DD.MM.YYYY','dd-mmm-yyyy'))&amp;nbsp;&lt;/P&gt;&lt;P&gt;min(Date#(Date("Date field")))&lt;/P&gt;&lt;P&gt;Date(Date#(min(num(right("Date field",4)&amp;amp;mid("Date field",4,2)&amp;amp;left("Date field",2)))))&lt;/P&gt;&lt;P&gt;Date(min("Date field"))&lt;/P&gt;&lt;P&gt;min(Date(Date#(replace("Valid to",'.','/'))))&lt;/P&gt;&lt;P&gt;The results I get is usually -- or&amp;nbsp; 28-Aug-275447 which I honestly don't know where it come from.&lt;/P&gt;&lt;P&gt;Do you have any suggestion?&lt;/P&gt;&lt;P&gt;The load I use is pretty simple:&lt;/P&gt;&lt;P&gt;LOAD&lt;BR /&gt;Material,&lt;BR /&gt;Min(num(right("Date field",4)&amp;amp;mid("Date field",4,2)&amp;amp;left("Date field",2))) as "Date field"&lt;/P&gt;&lt;P&gt;FROM [lib://NPI Data Readiness (eu_anori2)/PHARM REPORTING/SAP/ERP2 YI031.xls]&lt;BR /&gt;(txt, unicode, embedded labels, delimiter is '\t', msq, header is 3 lines)&lt;/P&gt;&lt;P&gt;group by Material;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 21:08:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1766030#M59257</guid>
      <dc:creator>aryx</dc:creator>
      <dc:date>2021-12-20T21:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the first expiring date (min function for date)</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1766479#M59297</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I hope this helps , i have added the load script. In the load script the &lt;EM&gt;&lt;STRONG&gt;&lt;U&gt;QlikTest&lt;/U&gt;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;table has the actual data , then from the QlikTest another table is resident loaded to get one extra column which converts the date into a num equivalent for min calculation and the table name is &lt;EM&gt;&lt;U&gt;QlikTestTransformed&lt;/U&gt;&lt;/EM&gt;. I have added the table chart screenshot for your reference as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;QlikTest:&lt;BR /&gt;Load * Inline&lt;BR /&gt;[&lt;BR /&gt;Material code, Date field&lt;BR /&gt;12345, 01.05.2022&lt;BR /&gt;12345, 12.11.2020&lt;BR /&gt;12345, 18.06.2021&lt;BR /&gt;6789, 31.12.9999&lt;BR /&gt;6789, 14.09.2021&lt;BR /&gt;3210, 31.12.9999&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;QlikTestTransformed:&lt;BR /&gt;load [Material code],&lt;BR /&gt;[Date field],&lt;BR /&gt;Num(SubField([Date field],.,3)&amp;amp;SubField([Date field],.,2)&amp;amp;SubField([Date field],.,1)) as dates resident QlikTest;&lt;/P&gt;&lt;P&gt;Drop Table QlikTest;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Screenshot of table object with min calculation of date:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2020-12-05 at 7.20.12 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/45280i9C73BED8DFB8A201/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2020-12-05 at 7.20.12 PM.png" alt="Screenshot 2020-12-05 at 7.20.12 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2020 13:54:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1766479#M59297</guid>
      <dc:creator>ibdK4evr</dc:creator>
      <dc:date>2020-12-05T13:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the first expiring date (min function for date)</title>
      <link>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1768685#M59465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I tried this solution and indeed works if I put the min() function in the table instead of in the script.&lt;/P&gt;&lt;P&gt;Won't table take more time to show data?&lt;/P&gt;&lt;P&gt;Furthermore, I won't see the field "dates" in the table but just the "Data Field", due to the fact I do have several columns reporting such kind of data and value is dates column would have a non-readable format.&lt;/P&gt;&lt;P&gt;I also tried to move the min() function in the script, as below:&lt;/P&gt;&lt;P&gt;min(Num(SubField("Date field",.,3)&amp;amp;SubField("Date field",.,2)&amp;amp;SubField("Date field",.,1))) as dates&amp;nbsp;&lt;/P&gt;&lt;P&gt;but then I need to group by date field as well, which will give a different result:&lt;/P&gt;&lt;P&gt;LOAD&lt;BR /&gt;Material,&lt;BR /&gt;"Date field",&lt;BR /&gt;Min(Num(SubField("Date field",.,3)&amp;amp;SubField("Date field",.,2)&amp;amp;SubField("Date field",.,1))) as "Date Field min"&lt;BR /&gt;resident table;&lt;BR /&gt;group by Material,"Date field";&lt;/P&gt;&lt;P&gt;Instead if I remove Date field of course I get the error, as usually for SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 17:06:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/How-to-select-the-first-expiring-date-min-function-for-date/m-p/1768685#M59465</guid>
      <dc:creator>aryx</dc:creator>
      <dc:date>2020-12-15T17:06:03Z</dc:date>
    </item>
  </channel>
</rss>

