<?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: Join two tables in order to calculate working hours in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065454#M87402</link>
    <description>&lt;P&gt;Works Perfect !&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Apr 2023 19:17:54 GMT</pubDate>
    <dc:creator>Sharbel</dc:creator>
    <dc:date>2023-04-27T19:17:54Z</dc:date>
    <item>
      <title>Join two tables in order to calculate working hours</title>
      <link>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2064781#M87332</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am trying to import working hours data from csv file&amp;nbsp; as shown below :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_2-1682575475666.png" style="width: 371px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105935iBE623B7013DEA6B2/image-dimensions/371x538?v=v2" width="371" height="538" role="button" title="Sharbel_2-1682575475666.png" alt="Sharbel_2-1682575475666.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;column a - employee number&lt;/P&gt;
&lt;P&gt;column b - date&lt;/P&gt;
&lt;P&gt;column c - time&amp;nbsp;&lt;/P&gt;
&lt;P&gt;column d - 100 stands for IN and 200 stands for OUT&lt;/P&gt;
&lt;P&gt;IN order to calculate working hours per employee, i thought of creating two tables as shown below:&lt;/P&gt;
&lt;P&gt;Table containing only IN's:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_4-1682577972497.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105943iA9D7CEAF98F6D7C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sharbel_4-1682577972497.png" alt="Sharbel_4-1682577972497.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and second table containing the OUT's:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_5-1682578052286.png" style="width: 670px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105944iECCC3E9A219C6BFC/image-dimensions/670x394?v=v2" width="670" height="394" role="button" title="Sharbel_5-1682578052286.png" alt="Sharbel_5-1682578052286.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note that beside morning and evening shifts (that starts and end within the same day) , there are unique types of working shifts as follows:&lt;/P&gt;
&lt;P&gt;Double Shift -&amp;nbsp; as shown below (in yellow) first shift started at between 07:00 - 10:00 and second shift between 14:00 - 18:00 (start and end may change)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_9-1682578476096.png" style="width: 572px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105948iA016A7D20DFC9CAA/image-dimensions/572x259?v=v2" width="572" height="259" role="button" title="Sharbel_9-1682578476096.png" alt="Sharbel_9-1682578476096.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_10-1682578517769.png" style="width: 602px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105949i6C90B4CE77A8566B/image-dimensions/602x270?v=v2" width="602" height="270" role="button" title="Sharbel_10-1682578517769.png" alt="Sharbel_10-1682578517769.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Night Shift - usually starts at between 22:00-23:00 and ends at 06:00-07:00 the &lt;U&gt;&lt;STRONG&gt;next day.&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_7-1682578320607.png" style="width: 563px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105946i639CBCEB02E8AE41/image-dimensions/563x161?v=v2" width="563" height="161" role="button" title="Sharbel_7-1682578320607.png" alt="Sharbel_7-1682578320607.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sharbel_8-1682578357952.png" style="width: 636px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105947iE57833CF79C91F7E/image-dimensions/636x169?v=v2" width="636" height="169" role="button" title="Sharbel_8-1682578357952.png" alt="Sharbel_8-1682578357952.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any ideas on how to calculate working hours?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks&lt;/P&gt;
&lt;P&gt;Sharbel&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;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&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>Thu, 27 Apr 2023 07:17:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2064781#M87332</guid>
      <dc:creator>Sharbel</dc:creator>
      <dc:date>2023-04-27T07:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables in order to calculate working hours</title>
      <link>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065429#M87397</link>
      <description>&lt;P&gt;here is one solution.&amp;nbsp; i separated the source tables and the transformed table so you can see them at the same time but you can optimize this for sure.&amp;nbsp; you need to transform your times into the acceptable format - that should be easy enough.&amp;nbsp; you then inner join them by employee&amp;nbsp;&lt;BR /&gt;then filter out the records where time out &amp;lt; time in&lt;BR /&gt;then group by emp and timein and get the min of the timeout.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;empIN:
load *, date(date(date_in) + Timestamp(time_in, 'M/D/YYYY hh:mm:ss[.fff]'),'M/D/YYYY hh:mm:ss[.fff]') as date_time_in inline [
emp_in, date_in, time_in
1995, 1/5/2023, 19:08:02
1995, 1/4/2023, 09:08:02
];

empOUT:
load *, date(date(date_out) + Timestamp(time_out, 'M/D/YYYY hh:mm:ss[.fff]'),'M/D/YYYY hh:mm:ss[.fff]') as date_time_out inline [
emp_out, date_out, time_out
1995, 1/6/2023, 07:08:02
1995, 1/4/2023, 23:08:02
];

NoConcatenate
tmp:
load 
	emp_in as emp, date_time_in as datetimein
Resident
	empIN;

inner join (tmp)
load 
	emp_out as emp, date_time_out as datetimeout
resident
	empOUT;
NoConcatenate
EMP:
load 
	emp, datetimein,
    date(min(datetimeout),'M/D/YYYY hh:mm:ss[.fff]') as datetimeout
Resident
	tmp
where datetimeout&amp;gt;=datetimein
group by emp, datetimein
;

drop table tmp;&lt;/LI-CODE&gt;
&lt;P&gt;here is how it looks:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_0-1682619456807.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/105985i23EFCEF337BEFFF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_0-1682619456807.png" alt="edwin_0-1682619456807.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;result is in hours, you can always floor it after deciding if you will show your duration in hrs, mins, etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 18:18:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065429#M87397</guid>
      <dc:creator>edwin</dc:creator>
      <dc:date>2023-04-27T18:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables in order to calculate working hours</title>
      <link>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065438#M87398</link>
      <description>&lt;P&gt;i should have added that the actual in and out should be date time format so the load does that first.&amp;nbsp; this way it address concerns where in and out are not on the same DAY&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 18:29:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065438#M87398</guid>
      <dc:creator>edwin</dc:creator>
      <dc:date>2023-04-27T18:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables in order to calculate working hours</title>
      <link>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065454#M87402</link>
      <description>&lt;P&gt;Works Perfect !&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:17:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Join-two-tables-in-order-to-calculate-working-hours/m-p/2065454#M87402</guid>
      <dc:creator>Sharbel</dc:creator>
      <dc:date>2023-04-27T19:17:54Z</dc:date>
    </item>
  </channel>
</rss>

