<?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: Calculated column: count days between two dates on calendar table where &amp;quot;IsWorkDay&amp;quot; fi in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1589402#M43209</link>
    <description>&lt;P&gt;An alternative solution using interval match, it might be an faster approach than the mapping method. See attached qvf.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Script using intervalMatch" style="width: 921px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13372i4909019A56B9F7E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="Script using intervalMatch" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Script using intervalMatch&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result in table using different total methods" style="width: 991px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13373iF7673389A1266920/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="Result in table using different total methods" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Result in table using different total methods&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jun 2019 08:22:58 GMT</pubDate>
    <dc:creator>Vegar</dc:creator>
    <dc:date>2019-06-07T08:22:58Z</dc:date>
    <item>
      <title>Calculated column: count days between two dates on calendar table where "IsWorkDay" field = 1</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588297#M43064</link>
      <description>&lt;P&gt;I have two tables, a CALENDAR table that has a custom calculation of IsWorkDay (I populate the IsWorkDay in the load script based on if the date occurs on a different table, so it doesn't follow a holiday or weekday schedule):&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;IsWorkDay&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/3/2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/4/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and an ORDER table:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Order&lt;/TD&gt;&lt;TD&gt;StartDate&lt;/TD&gt;&lt;TD&gt;EndDate&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;WorkDays (Expected Result)&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;0&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/4/2019&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;1&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;2&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;1&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;1/3/2019&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;0&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;0&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it matters, my tables in Qlik Sense are joined on Calendar.Date = Orders.StartDate.&lt;/P&gt;&lt;P&gt;I've done this in PowerPivot with a calculated column on my ORDER table using the following expression and got my intended results, I just can't figure out how to best handle it in Qlik Sense:&lt;/P&gt;&lt;P&gt;CALCULATE(&lt;BR /&gt;COUNTROWS(CALENDAR),&lt;BR /&gt;DATESBETWEEN('Calendar'[Date],ORDER[StartDate],ORDER[EndDate]),&lt;BR /&gt;'Calendar'[IsWorkDay]=1&lt;BR /&gt;) - 1)&lt;/P&gt;&lt;P&gt;I'd prefer to figure out how to handle this as a calculated column in Qlik Sense. Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 05:40:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588297#M43064</guid>
      <dc:creator>Den</dc:creator>
      <dc:date>2024-11-16T05:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column: count days between two dates on calendar table where "IsWorkDay" fi</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588334#M43072</link>
      <description>I find yor expected result hard to understand. Which day in the interval are you excluding, the first or the last? In Order 1 it seems like you are excluding the first (1/1/2019) but on order 4 you are excluding the last (1/5/2019).&lt;BR /&gt;&lt;BR /&gt;If your expected values are correct then please explain for each row which workdays you are counting.</description>
      <pubDate>Tue, 04 Jun 2019 19:16:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588334#M43072</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2019-06-04T19:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column: count days between two dates on calendar table where "IsWorkDay" fi</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588338#M43073</link>
      <description>&lt;P&gt;My previous question is still valid, but I did a solution assuming you want to disregard the first date in the interval as potential working day.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MAP_Workday:
MAPPING LOAD * 
inline [
  Date,IsWorkDay
  1/1/2019,1
  1/2/2019,0
  1/3/2019,0
  1/4/2019,1
  1/5/2019,1];

Order:
LOAD * 
Inline [
  Order,StartDate,EndDate,WorkDays (Expected Result)
  1,1/1/2019,1/2/2019,0
  2,1/1/2019,1/4/2019,1
  3,1/1/2019,1/5/2019,2
  4,1/2/2019,1/5/2019,1
  5,1/2/2019,1/3/2019,0
  6,1/5/2019,1/5/2019,0];

left join LOAD 
  sum(Workday) as  Workdays,
  Order
Group by 
  Order;
LOAD 
  Order,
  applymap('MAP_Workday',StartDate  + IterNo(),0) as Workday
Resident 
  Order
while 
  StartDate  + IterNo() &amp;lt;= EndDate;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives me this table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 962px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13185iD0653D93419E0D76/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 19:34:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588338#M43073</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2019-06-04T19:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column: count days between two dates on calendar table where "IsWorkDay" fi</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588673#M43130</link>
      <description>&lt;P&gt;Oops, your statements are correct. The intended result was a mix-up on my part, it just needs to be the amount of business days between two dates minus 1 day. If the item was started and stopped on the same day, it would be zero days. If the item was started and stopped during a time period where there weren't any working days, then the calculation should give it a -1, which I will handle as zeroes in my KPI calculation.&lt;/P&gt;&lt;P&gt;I've been trying to implement your solution and I believe the issues I'm having is that my solution is using the GUI to synchronize tables after I import them to handle the relationships, so at the time of the load, there isn't a relationship made between my CALENDAR and ORDERS tables. It cannot determine a relationship in order to calculate this part of the script:&lt;/P&gt;&lt;PRE&gt;left join LOAD 
  sum(Workday) as  Workdays,
  Order&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 15:12:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588673#M43130</guid>
      <dc:creator>Den</dc:creator>
      <dc:date>2019-06-05T15:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column: count days between two dates on calendar table where "IsWorkDay" fi</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588729#M43139</link>
      <description>&lt;P&gt;I got your script to work. Your calculations work perfectly and it is giving exactly my intended results (you were correct on how it should be calculating the amount of work days, it was my mix-up with putting in the incorrect expected result for the row of order 4). Thanks a ton, Vegar!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 17:54:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1588729#M43139</guid>
      <dc:creator>Den</dc:creator>
      <dc:date>2019-06-05T17:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column: count days between two dates on calendar table where "IsWorkDay" fi</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1589402#M43209</link>
      <description>&lt;P&gt;An alternative solution using interval match, it might be an faster approach than the mapping method. See attached qvf.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Script using intervalMatch" style="width: 921px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13372i4909019A56B9F7E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="Script using intervalMatch" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Script using intervalMatch&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result in table using different total methods" style="width: 991px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13373iF7673389A1266920/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="Result in table using different total methods" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Result in table using different total methods&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 08:22:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1589402#M43209</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2019-06-07T08:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column: count days between two dates on calendar table where "IsWorkDay" fi</title>
      <link>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1589636#M43224</link>
      <description>&lt;P&gt;I will try IntervalMatch to see if it is faster. As it turns out, I need to calculate my orders based on a column on the table, and then calculate the work days between the StartDate and EndDate based on two different IsWorkDay columns. So this is what my tables look like now:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;IsWorkDay_AreaA&lt;/TD&gt;&lt;TD&gt;IsWork_Day_AreaB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/3/2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/4/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ORDER:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OrderNo&lt;/TD&gt;&lt;TD&gt;OrderArea&lt;/TD&gt;&lt;TD&gt;StartDate&lt;/TD&gt;&lt;TD&gt;EndDate&lt;/TD&gt;&lt;TD&gt;WorkDays (Expected Result)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/2/1019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1/1/2019&lt;/TD&gt;&lt;TD&gt;1/4/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;1/4/2019&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/2/2019&lt;/TD&gt;&lt;TD&gt;1/5/2019&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to use this logic with an IntervalMatch? I tried implementing the original solution by mapping IsWorkDay_AreaA and filtering results on my orders where OrderArea='A' and it worked. When I tried to concatenate the orders by mapping IsWorkDay_AreaB and filtering results on my orders where OrderArea='B', it calculated the WorkDays for the orders in OrderAreaA, but the WorkDays for OrderAreaB were all null.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 14:53:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculated-column-count-days-between-two-dates-on-calendar-table/m-p/1589636#M43224</guid>
      <dc:creator>Den</dc:creator>
      <dc:date>2019-06-07T14:53:23Z</dc:date>
    </item>
  </channel>
</rss>

