<?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: Year presence ratio between 2 dates in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047339#M86137</link>
    <description>&lt;P&gt;Hi Marijn,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your reply.&lt;/P&gt;
&lt;P&gt;It's a great start, but what should I add to the expression to only have results for 2022 presence?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because if I have a start date = 01/01/2021&amp;nbsp; and end date = &lt;SPAN&gt;30/06/2022&amp;nbsp;&lt;/SPAN&gt;for instance , with the present expression I obtain 1,49589 where I need 0,49589&lt;/P&gt;
&lt;P&gt;Thanks again for your help&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2023 11:25:44 GMT</pubDate>
    <dc:creator>psunny0070</dc:creator>
    <dc:date>2023-03-09T11:25:44Z</dc:date>
    <item>
      <title>Year presence ratio between 2 dates</title>
      <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047013#M86118</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm seeking help to include in load script a calculated field we could name [Year Presence], starting from 2 date fields, [Start date] and [End date].&lt;/P&gt;
&lt;P&gt;I'm actually trying to replicate something I have done in excel, but with quite complex formulas:&lt;/P&gt;
&lt;TABLE width="285"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="108"&gt;Start Date&lt;/TD&gt;
&lt;TD width="83"&gt;End Date&lt;/TD&gt;
&lt;TD width="94"&gt;2022 Presence&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;01/01/2022&lt;/TD&gt;
&lt;TD&gt;30/06/2022&lt;/TD&gt;
&lt;TD&gt;0,50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;01/01/2022&lt;/TD&gt;
&lt;TD&gt;31/03/2022&lt;/TD&gt;
&lt;TD&gt;0,25&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The context is members arriving on a given date and then leaving . I need to obtain the presence ratio on a given year.&lt;/P&gt;
&lt;P&gt;(if no end date in the above examples, then value would be '1')&lt;/P&gt;
&lt;P&gt;What would be the best way to obtain "Presence" value for a given year as a calculated field in the loading script?&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance for your help, as I'm running in circles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 18:14:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047013#M86118</guid>
      <dc:creator>psunny0070</dc:creator>
      <dc:date>2023-03-08T18:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Year presence ratio between 2 dates</title>
      <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047319#M86136</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;You could consider using the following:&lt;/P&gt;
&lt;P&gt;( (floor([End Date])+1) - floor[Start Date]) / ( floor(YearEnd([Start Date])+1) - floor(YearStart([Start Date])) )&lt;/P&gt;
&lt;P&gt;That would be something like this with your data example:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;((floor([30/06/2022])+1) - floor([01/01/2022]) / ( floor(YearEnd([01/01/2022])+1) - floor(YearStart([01/01/2022])) )&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;=&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;(44743 - 44562) / (44926 - 44562)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;=&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;181 / 365 = 0,49589&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;This will give you the percentage of days present in that year.&lt;BR /&gt;&lt;BR /&gt;Hope it helps!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 10:58:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047319#M86136</guid>
      <dc:creator>Marijn</dc:creator>
      <dc:date>2023-03-09T10:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Year presence ratio between 2 dates</title>
      <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047339#M86137</link>
      <description>&lt;P&gt;Hi Marijn,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your reply.&lt;/P&gt;
&lt;P&gt;It's a great start, but what should I add to the expression to only have results for 2022 presence?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because if I have a start date = 01/01/2021&amp;nbsp; and end date = &lt;SPAN&gt;30/06/2022&amp;nbsp;&lt;/SPAN&gt;for instance , with the present expression I obtain 1,49589 where I need 0,49589&lt;/P&gt;
&lt;P&gt;Thanks again for your help&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 11:25:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047339#M86137</guid>
      <dc:creator>psunny0070</dc:creator>
      <dc:date>2023-03-09T11:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Year presence ratio between 2 dates</title>
      <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047417#M86145</link>
      <description>&lt;P&gt;To make it flexible, so you don't have to change anything to the script next year, I'd use a variable to determine which year to calculate:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;let vYear = year(today()) - 1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Then the expression should be something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;if(floor([Start Date]) &amp;lt; floor('01-01-$(vYear)') and floor([End Date]) &amp;gt; floor('31-12-$(vYear)'),   1,
    if(floor([Start Date]) &amp;lt; floor('01-01-$(vYear)'),   ((floor([End Date])+1) - floor('01-01-$(vYear)')    / ( floor('31-12-$(vYear)') +1) - floor('01-01-$(vYear)')),
    if(floor([End Date]) &amp;gt; floor('31-12-$(vYear)'),     ((floor('31-12-$(vYear)')+1) - floor([Start Date])  / ( floor('31-12-$(vYear)') +1) - floor('01-01-$(vYear)'))
    )))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Beware I didn't test the expression, so there might be a typo somewhere. The general approach is:&lt;BR /&gt;&lt;BR /&gt;- if-statement 1: IF start date is before 1-1-vYear AND end date is after 31-12-vYear THEN 1,&lt;BR /&gt;- if-statement 2: IF start date is before 1-1-vYear, calculate number of days between 1-1-vYear and End date and divide by number of days in vYear&lt;BR /&gt;- if-statement 3: IF end date is after 31-12-vYear, calculate number of days between start date and 31-12-vYear and divide by number of days in vYear&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 13:56:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047417#M86145</guid>
      <dc:creator>Marijn</dc:creator>
      <dc:date>2023-03-09T13:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Year presence ratio between 2 dates</title>
      <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047601#M86167</link>
      <description>&lt;P&gt;Thanks a lot , I tried this but I now always obtain blank values, I wonder why?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 19:48:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2047601#M86167</guid>
      <dc:creator>psunny0070</dc:creator>
      <dc:date>2023-03-09T19:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Year presence ratio between 2 dates</title>
      <link>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2048017#M86183</link>
      <description>&lt;P&gt;Hi Marijn,&lt;/P&gt;
&lt;P&gt;Just to let you know I finally obtained values with&amp;nbsp;('01/01/'&amp;amp;$(vYear)) and ('31/12/'&amp;amp;$(vYear)) instead.&lt;/P&gt;
&lt;P&gt;But strangely I need to divide the whole calculated field by 365 to obtain the ratio, otherwise I just obtain the difference in number of days.&lt;/P&gt;
&lt;P&gt;Thanks again for all your help here.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 16:55:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Year-presence-ratio-between-2-dates/m-p/2048017#M86183</guid>
      <dc:creator>psunny0070</dc:creator>
      <dc:date>2023-03-10T16:55:18Z</dc:date>
    </item>
  </channel>
</rss>

