<?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: Calculating Time Duration With Conditions in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519435#M37116</link>
    <description>&lt;P&gt;Found a hole in the loop...&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.qlik.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;See File attached... when there are more than 2 visits in the same time frame&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Dec 2018 09:35:52 GMT</pubDate>
    <dc:creator>sogloqlik</dc:creator>
    <dc:date>2018-12-12T09:35:52Z</dc:date>
    <item>
      <title>Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1518588#M37064</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I have the following User Demand:&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a table (attached) with Salesman, Customer, Date, Visit ID, Start Time and End Time.&lt;/P&gt;&lt;P&gt;I&amp;nbsp;need to calculate the duration of the visit of the salesman&amp;nbsp;made to&amp;nbsp;a customer.&lt;/P&gt;&lt;P&gt;To begin with, there is an option that there will be more than one visit per day.&lt;/P&gt;&lt;P&gt;Now, let's assume that there are 2 visits per day:&lt;/P&gt;&lt;P&gt;If the&amp;nbsp; second visit starts within 15 Min of the end of the first visit - I have to look at both visit as one and to take the start time from the first visit and the end time of the second visit and this is the Duration.&lt;/P&gt;&lt;P&gt;If the second visit start after 15 min. It means that they are separate visits and then I have to sum the duration of each visit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example attached:&lt;/P&gt;&lt;P&gt;For the 08.08.2018 the duration will be 60 Min.&lt;/P&gt;&lt;P&gt;For the 09.08.2018 the duration will be 45 Min.&lt;/P&gt;&lt;P&gt;Again, there could be one, two or more visits per day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve it (either in the script or GUI?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx.&lt;/P&gt;&lt;P&gt;Motty&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 11:27:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1518588#M37064</guid>
      <dc:creator>sogloqlik</dc:creator>
      <dc:date>2018-12-10T11:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1518640#M37065</link>
      <description>&lt;P&gt;May be a hybrid of script + UI based solution&lt;/P&gt;&lt;P&gt;Script&lt;/P&gt;&lt;PRE&gt;Table:
LOAD [Sales Man], 
     Customer, 
     [Visit ID], 
     Date(Date#(Date, 'MM.DD.YYYY')) as Date, 
     [Start Time], 
     [End Time]
FROM
[..\..\Downloads\Visit Duration.xlsx]
(ooxml, embedded labels, table is גיליון1);

FinalTable:
LOAD *,
	 If([Sales Man] = Previous([Sales Man]) and Customer = Previous(Customer) and Date = Previous(Date),
	 If([Start Time] - Previous([End Time]) &amp;lt;= MakeTime(0, 15), Previous([Start Time]), [Start Time]), [Start Time]) as [New Start Time],
	 If([Sales Man] = Previous([Sales Man]) and Customer = Previous(Customer) and Date = Previous(Date),
	 If([Start Time] - Previous([End Time]) &amp;lt;= MakeTime(0, 15), Previous([Visit ID]), [Visit ID]), [Visit ID]) as [New Visit ID]
Resident Table
Order By [Sales Man], Customer, Date, [Visit ID];

DROP Table Table;&lt;/PRE&gt;&lt;P&gt;Front end&lt;/P&gt;&lt;P&gt;Dimension&lt;/P&gt;&lt;PRE&gt;Date&lt;/PRE&gt;&lt;P&gt;Expression&lt;/P&gt;&lt;PRE&gt;Interval(Sum(Aggr(Max([End Time]) - [New Start Time], Date, [New Visit ID])), 'mm')&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Dec 2018 12:29:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1518640#M37065</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-12-10T12:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1518647#M37066</link>
      <description>&lt;P&gt;Works fine&lt;/P&gt;&lt;P&gt;Thanks a&amp;nbsp; lot&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 13:38:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1518647#M37066</guid>
      <dc:creator>sogloqlik</dc:creator>
      <dc:date>2018-12-10T13:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519435#M37116</link>
      <description>&lt;P&gt;Found a hole in the loop...&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.qlik.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;See File attached... when there are more than 2 visits in the same time frame&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 09:35:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519435#M37116</guid>
      <dc:creator>sogloqlik</dc:creator>
      <dc:date>2018-12-12T09:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519821#M37151</link>
      <description>What is the expected output in this case?</description>
      <pubDate>Wed, 12 Dec 2018 12:46:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519821#M37151</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-12-12T12:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519829#M37152</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expected output would be that the first 3 rows would be considered as one visit. which means same new VisitID, New starttime from the first row, NewendTime from the third row. Total duration of two hours.&lt;/P&gt;&lt;P&gt;there may be a case where i would need to combine 4 rows and even 5. i dont know it in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 12:57:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519829#M37152</guid>
      <dc:creator>sogloqlik</dc:creator>
      <dc:date>2018-12-12T12:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519840#M37154</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;&lt;PRE&gt;Table:
LOAD [Sales Man], 
     Customer, 
     [Visit ID], 
     Date(Date#(Date, 'MM.DD.YYYY')) as Date, 
     [Start Time], 
     [End Time]
FROM
[..\..\Downloads\Visit Duration (1).xlsx]
(ooxml, embedded labels, table is גיליון1);

FinalTable:
LOAD *,
	 If([Sales Man] = Previous([Sales Man]) and Customer = Previous(Customer) and Date = Previous(Date),
	 If([Start Time] - Previous([End Time]) &amp;lt;= MakeTime(0, 15), &lt;FONT color="#FF0000"&gt;Peek('New Start Time')&lt;/FONT&gt;, [Start Time]), [Start Time]) as [New Start Time],
	 If([Sales Man] = Previous([Sales Man]) and Customer = Previous(Customer) and Date = Previous(Date),
	 If([Start Time] - Previous([End Time]) &amp;lt;= MakeTime(0, 15), &lt;FONT color="#FF0000"&gt;Peek('New Visit ID')&lt;/FONT&gt;, [Visit ID]), [Visit ID]) as [New Visit ID]
Resident Table
Order By [Sales Man], Customer, Date, [Visit ID];

DROP Table Table;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 551px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/2051iA4D94FD421913542/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 13:07:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519840#M37154</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-12-12T13:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519852#M37156</link>
      <description>&lt;P&gt;Now it seems to be working.&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.qlik.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;Can you please explain me the difference? How does Peek works in such a case?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 13:21:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519852#M37156</guid>
      <dc:creator>sogloqlik</dc:creator>
      <dc:date>2018-12-12T13:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519853#M37157</link>
      <description>Peek can iteratively look at the value just created in the previous row.... so, instead of looking at Previous([Start Time])... I started looking at Peek('New Start Time'). I wanted to pull the value of Start Time not based on Start Time, but the new field that I created.&lt;BR /&gt;&lt;BR /&gt;Does that make sense?</description>
      <pubDate>Wed, 12 Dec 2018 13:24:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519853#M37157</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2018-12-12T13:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Time Duration With Conditions</title>
      <link>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519856#M37159</link>
      <description>&lt;P&gt;Totaly&lt;/P&gt;&lt;P&gt;Very Elegant&amp;nbsp; solution&lt;/P&gt;&lt;P&gt;Thx&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.qlik.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 13:34:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculating-Time-Duration-With-Conditions/m-p/1519856#M37159</guid>
      <dc:creator>sogloqlik</dc:creator>
      <dc:date>2018-12-12T13:34:14Z</dc:date>
    </item>
  </channel>
</rss>

