<?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: Difference between two dates (when matching another field) in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038688#M85572</link>
    <description>&lt;P&gt;In your formula, replace &lt;EM&gt;[Date Out]&lt;/EM&gt; with &lt;EM&gt;alt([Date Out], today(1))&lt;/EM&gt; &lt;BR /&gt;If [Date Out] is NULL or blank then today's date will be used instead.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2023 12:02:20 GMT</pubDate>
    <dc:creator>henrikalmen</dc:creator>
    <dc:date>2023-02-16T12:02:20Z</dc:date>
    <item>
      <title>Difference between two dates (when matching another field)</title>
      <link>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038125#M85528</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Bit difficult to explain this one but,&lt;/P&gt;
&lt;P&gt;I want to chart the difference in days, between dates. The two date's are in the same field but with a different flag (MvT).&lt;/P&gt;
&lt;P&gt;The other factor is that all of these entries are related to a batch number, each batch number should have two entries, the Date In (MvT = 501) and the Date Out (MvT = 281) (there are a few exceptions which have more than one date in or out, due to poor master data that is being worked on, and for now will just skew the figures).&lt;/P&gt;
&lt;P&gt;I would then chart it ideally by&amp;nbsp; Entry Date&amp;nbsp; (autocalendar week), or if not possible then by batch number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally when charting difference in two dates I use;&lt;/P&gt;
&lt;P&gt;AVG (Ceil(Interval(Date#([Date field1], 'DD.MM.YYYY') - Date# ([datefield2], 'DD.MM.YYYY'), 'D' )) )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought to make this work, I needed to perhaps create new separate date fields for the two MvT types, so in the load script I used;&lt;/P&gt;
&lt;P&gt;Entry Date],&lt;BR /&gt;If(MvT = '281', [Entry Date]) AS [Date Out],&lt;BR /&gt;If(MvT = '501', [Entry Date]) AS [Date In],&lt;/P&gt;
&lt;P&gt;then as my&amp;nbsp; measure,&lt;/P&gt;
&lt;P&gt;avg (Ceil(Interval(Date#([Date Out], 'DD.MM.YYYY') - Date# ([Date In], 'DD.MM.YYYY'), 'D' )) )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached example data of what I am using.&lt;/P&gt;
&lt;P&gt;The Date In and Date Out look to be okay in a table and I have highlighted some of the data showing both dates against a batch in the below image. Not every batch will have both and again if it is possible I would like to show the days for those that do not have a Date Out (MvT&amp;nbsp; = 281) as the difference from the Date In (MvT =501) against 'today'.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daryn_0-1676452025036.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100544i6DC0DAB410880408/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daryn_0-1676452025036.png" alt="Daryn_0-1676452025036.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;My current results are blank as below if I use either Entry&amp;nbsp; Date or Batch as dimension.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daryn_1-1676452253991.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100545iD177A746288DC19E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daryn_1-1676452253991.png" alt="Daryn_1-1676452253991.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, that's a headache to explain let alone work out!&lt;/P&gt;
&lt;P&gt;Appreciate the time and effort anyone puts into looking or even reading this!&lt;/P&gt;
&lt;P&gt;Regards as always,&lt;/P&gt;
&lt;P&gt;Daryn&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 09:13:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038125#M85528</guid>
      <dc:creator>Daryn</dc:creator>
      <dc:date>2023-02-15T09:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates (when matching another field)</title>
      <link>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038250#M85534</link>
      <description>&lt;P&gt;I'm not certain that I completely understand what you want to do, but in the image where you have marked lines with yellow I think you'd want one row per batch and not two rows.&lt;/P&gt;
&lt;P&gt;To achieve that you could join data in load script. Instead of having if-clauses creating Date In and Date out, do something like this to create a new table:&lt;/P&gt;
&lt;P&gt;[dateInOut]: load distinct Batch resident [Entry Date];&lt;BR /&gt;left join([dateInOut]) load Batch, [Entry Date]) AS [Date In] resident [Entry Date] where MvT = '501';&lt;BR /&gt;left join([dateInOut]) load Batch, [Entry Date]) AS [Date Out] resident [Entry Date] where MvT = '281';&lt;/P&gt;
&lt;P&gt;This may not solve your entire task but it's possibly a step on the way.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 13:53:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038250#M85534</guid>
      <dc:creator>henrikalmen</dc:creator>
      <dc:date>2023-02-15T13:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates (when matching another field)</title>
      <link>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038563#M85559</link>
      <description>&lt;P&gt;I did very crudely, get this working using my load script values of;&lt;/P&gt;
&lt;P&gt;If(MvT = '281', [Entry Date]) AS [Date Out],&lt;BR /&gt;If(MvT = '501', [Entry Date]) AS [Date In],&lt;/P&gt;
&lt;P&gt;Then 'Batch' as the dimension and 'date((date([Date Out],'DD.MM.YYYY')-date([Date In],'DD.MM.YYYY')),'DD')' as the measure.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daryn_0-1676535659450.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100646iE8FF838A552D51F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daryn_0-1676535659450.png" alt="Daryn_0-1676535659450.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As mentioned, very crude!&lt;/P&gt;
&lt;P&gt;So this shows me the number of days difference between booked in and out as such.&lt;/P&gt;
&lt;P&gt;However, I would like the Batches with no Date Out to calculate against today's date if possible?&lt;/P&gt;
&lt;P&gt;Thanks again for anyone who reads this or can assist.&lt;/P&gt;
&lt;P&gt;Appreciated.&lt;/P&gt;
&lt;P&gt;Daryn&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 08:26:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038563#M85559</guid>
      <dc:creator>Daryn</dc:creator>
      <dc:date>2023-02-16T08:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between two dates (when matching another field)</title>
      <link>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038688#M85572</link>
      <description>&lt;P&gt;In your formula, replace &lt;EM&gt;[Date Out]&lt;/EM&gt; with &lt;EM&gt;alt([Date Out], today(1))&lt;/EM&gt; &lt;BR /&gt;If [Date Out] is NULL or blank then today's date will be used instead.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 12:02:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Difference-between-two-dates-when-matching-another-field/m-p/2038688#M85572</guid>
      <dc:creator>henrikalmen</dc:creator>
      <dc:date>2023-02-16T12:02:20Z</dc:date>
    </item>
  </channel>
</rss>

