<?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 Dynamic Calculation of Event Duration Depending on Selected Time Range in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2005162#M83185</link>
    <description>&lt;P&gt;Dear Qlik Community,&lt;/P&gt;
&lt;P&gt;I would like to calculate the duration of an event even when a time range is selected that is smaller than the event itself.&lt;/P&gt;
&lt;P&gt;Here is a simplified example:&lt;/P&gt;
&lt;P&gt;I have a table with machine events kind of like this:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Events:&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE border="1" width="97.92682926829268%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;EventID&lt;/TD&gt;
&lt;TD width="20%"&gt;MachineID&lt;/TD&gt;
&lt;TD width="20%"&gt;Status&lt;/TD&gt;
&lt;TD width="20%"&gt;Start&lt;/TD&gt;
&lt;TD width="20%"&gt;End&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;1&lt;/TD&gt;
&lt;TD width="20%"&gt;100&lt;/TD&gt;
&lt;TD width="20%"&gt;Production&lt;/TD&gt;
&lt;TD width="20%"&gt;01.11.2022 15:00:00&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;2&lt;/TD&gt;
&lt;TD width="20%"&gt;100&lt;/TD&gt;
&lt;TD width="20%"&gt;Downtime&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:00:00&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:30:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;3&lt;/TD&gt;
&lt;TD width="20%"&gt;100&lt;/TD&gt;
&lt;TD width="20%"&gt;Production&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:30:00&lt;/TD&gt;
&lt;TD width="20%"&gt;16.11.2022 10:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;SPAN&gt;(Date format is DD.MM.YYYY hh.mm.ss)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;My measures then are like&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Event duration (minutes)&lt;/EM&gt;: Sum(End-Start)*24*60&lt;BR /&gt;&lt;EM&gt;Production time&lt;/EM&gt;:&amp;nbsp;Sum({$&amp;lt;Status={'Production'}&amp;gt;} End-Start)*24*60&lt;BR /&gt;&lt;EM&gt;Downtime&lt;/EM&gt;:&amp;nbsp;Sum({$&amp;lt;Status={'Downtime'}&amp;gt;} End-Start)*24*60&lt;/P&gt;
&lt;P&gt;Everything is fine until here.&lt;/P&gt;
&lt;P&gt;Now I want to know for each day, week, month, year,... how long the machine produced and how long it was in Downtime. But when I use&amp;nbsp;&lt;EM&gt;Start&lt;/EM&gt;&amp;nbsp; as a filter dimension and I filter e.g. the 02.11.2022, production and downtime is obviously zero because there is no &lt;EM&gt;Start&lt;/EM&gt; on 02.11.2022.&amp;nbsp;&lt;SPAN&gt;What I want to see is Production time = 24 h.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If I filter 12.11.2022 I would like to see Production time = 23,5 h, Downtime = 0,5 h.&lt;/P&gt;
&lt;P&gt;So &lt;EM&gt;Start&lt;/EM&gt;&amp;nbsp; does not seem to be the right dimension to filter by, but what else could I use?&lt;/P&gt;
&lt;P&gt;I already tried a solution that works but is very inefficient. I stored every single minute an event is active in a seperate table like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Event_Duration:
LOAD 
	Timestamp(Start + ((IterNo()-1)/(24*60))) as Active_Timestamp,
	EventID
Resident Events While Start + ((IterNo()-1)/(24*60)) &amp;lt;= End;  &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the App I use &lt;EM&gt;Active_Timestamp&lt;/EM&gt; as filter dimension and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Count(Active_Timestamp) as my measure &lt;EM&gt;Event duration (minutes).&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works fine but to store every single minute of every event of our more than 100 machines does not seem to be the right solution for me. I am getting time out errors with a limited data set already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have some ideas or inspiration for me? Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2022 09:36:20 GMT</pubDate>
    <dc:creator>Maike151</dc:creator>
    <dc:date>2022-11-16T09:36:20Z</dc:date>
    <item>
      <title>Dynamic Calculation of Event Duration Depending on Selected Time Range</title>
      <link>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2005162#M83185</link>
      <description>&lt;P&gt;Dear Qlik Community,&lt;/P&gt;
&lt;P&gt;I would like to calculate the duration of an event even when a time range is selected that is smaller than the event itself.&lt;/P&gt;
&lt;P&gt;Here is a simplified example:&lt;/P&gt;
&lt;P&gt;I have a table with machine events kind of like this:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Events:&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE border="1" width="97.92682926829268%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;EventID&lt;/TD&gt;
&lt;TD width="20%"&gt;MachineID&lt;/TD&gt;
&lt;TD width="20%"&gt;Status&lt;/TD&gt;
&lt;TD width="20%"&gt;Start&lt;/TD&gt;
&lt;TD width="20%"&gt;End&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;1&lt;/TD&gt;
&lt;TD width="20%"&gt;100&lt;/TD&gt;
&lt;TD width="20%"&gt;Production&lt;/TD&gt;
&lt;TD width="20%"&gt;01.11.2022 15:00:00&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;2&lt;/TD&gt;
&lt;TD width="20%"&gt;100&lt;/TD&gt;
&lt;TD width="20%"&gt;Downtime&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:00:00&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:30:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;3&lt;/TD&gt;
&lt;TD width="20%"&gt;100&lt;/TD&gt;
&lt;TD width="20%"&gt;Production&lt;/TD&gt;
&lt;TD width="20%"&gt;12.11.2022 12:30:00&lt;/TD&gt;
&lt;TD width="20%"&gt;16.11.2022 10:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;SPAN&gt;(Date format is DD.MM.YYYY hh.mm.ss)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;My measures then are like&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Event duration (minutes)&lt;/EM&gt;: Sum(End-Start)*24*60&lt;BR /&gt;&lt;EM&gt;Production time&lt;/EM&gt;:&amp;nbsp;Sum({$&amp;lt;Status={'Production'}&amp;gt;} End-Start)*24*60&lt;BR /&gt;&lt;EM&gt;Downtime&lt;/EM&gt;:&amp;nbsp;Sum({$&amp;lt;Status={'Downtime'}&amp;gt;} End-Start)*24*60&lt;/P&gt;
&lt;P&gt;Everything is fine until here.&lt;/P&gt;
&lt;P&gt;Now I want to know for each day, week, month, year,... how long the machine produced and how long it was in Downtime. But when I use&amp;nbsp;&lt;EM&gt;Start&lt;/EM&gt;&amp;nbsp; as a filter dimension and I filter e.g. the 02.11.2022, production and downtime is obviously zero because there is no &lt;EM&gt;Start&lt;/EM&gt; on 02.11.2022.&amp;nbsp;&lt;SPAN&gt;What I want to see is Production time = 24 h.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If I filter 12.11.2022 I would like to see Production time = 23,5 h, Downtime = 0,5 h.&lt;/P&gt;
&lt;P&gt;So &lt;EM&gt;Start&lt;/EM&gt;&amp;nbsp; does not seem to be the right dimension to filter by, but what else could I use?&lt;/P&gt;
&lt;P&gt;I already tried a solution that works but is very inefficient. I stored every single minute an event is active in a seperate table like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Event_Duration:
LOAD 
	Timestamp(Start + ((IterNo()-1)/(24*60))) as Active_Timestamp,
	EventID
Resident Events While Start + ((IterNo()-1)/(24*60)) &amp;lt;= End;  &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the App I use &lt;EM&gt;Active_Timestamp&lt;/EM&gt; as filter dimension and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Count(Active_Timestamp) as my measure &lt;EM&gt;Event duration (minutes).&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works fine but to store every single minute of every event of our more than 100 machines does not seem to be the right solution for me. I am getting time out errors with a limited data set already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have some ideas or inspiration for me? Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:36:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2005162#M83185</guid>
      <dc:creator>Maike151</dc:creator>
      <dc:date>2022-11-16T09:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Calculation of Event Duration Depending on Selected Time Range</title>
      <link>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2005811#M83227</link>
      <description>&lt;P&gt;as below&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;temp:
Load *
,date(Startdate+iterno()-1) as DailyDate
,if(Startdate=date(Startdate+iterno()-1) , interval(Time#('23:59','hh:mm')-Starttime,'hh')
	,if(Enddate=date(Startdate+iterno()-1) 
    	, hour(Endtime)
        	, 24) )as Hours
while (Startdate+IterNo()-1)&amp;lt;=Enddate
;
load 
EventID
,MachineID
,Status
,Timestamp(Timestamp#(Start,'DD.MM.YYYY hh:mm:ss')) as Starttimestamp
,timestamp(Timestamp#(End,'DD.MM.YYYY hh:mm:ss')) as Endtimestamp
,date(floor(Timestamp#(Start,'DD.MM.YYYY hh:mm:ss'))) as Startdate
,date(floor(Timestamp#(End,'DD.MM.YYYY hh:mm:ss'))) as Enddate
,time(timestamp(Frac(Timestamp#(Start,'DD.MM.YYYY hh:mm:ss')))) as Starttime
,time(timestamp(frac(Timestamp#(End,'DD.MM.YYYY hh:mm:ss')))) as Endtime
inline [
EventID,MachineID,Status,Start,End
1,100,Production,01.11.2022 15:00:00,12.11.2022 12:00:00
2,100,Downtime,12.11.2022 12:00:00,12.11.2022 12:30:00
3,100,Production,12.11.2022 12:30:00,16.11.2022 10:00:00
];
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;sum(Hours)&amp;nbsp; in chart and create calendar linked to DailyDate field&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/93973i7FA68C4A5CB8EDD7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 11:02:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2005811#M83227</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-11-17T11:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Calculation of Event Duration Depending on Selected Time Range</title>
      <link>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2014386#M83832</link>
      <description>&lt;P&gt;Thank you very much!!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 14:20:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Dynamic-Calculation-of-Event-Duration-Depending-on-Selected-Time/m-p/2014386#M83832</guid>
      <dc:creator>Maike151</dc:creator>
      <dc:date>2022-12-08T14:20:10Z</dc:date>
    </item>
  </channel>
</rss>

