<?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: Time Average - dealing with  irregular intervals in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1940256#M77503</link>
    <description>&lt;P&gt;Thanks Marco and Or for you valuable input! I wouldn't have figured it out otherwise.&lt;/P&gt;
&lt;P&gt;It was quite testing and took a few hours, but I finally managed to overcome the issue by calculating based on duration/proportion of an hour.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2022 09:57:29 GMT</pubDate>
    <dc:creator>HillVi</dc:creator>
    <dc:date>2022-06-07T09:57:29Z</dc:date>
    <item>
      <title>Time Average - dealing with  irregular intervals</title>
      <link>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1935316#M77055</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;
&lt;P&gt;I am trying to calculate average value per hour. However, the data I have is in irregular intervals. For instance:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="24px"&gt;&lt;STRONG&gt;Timestamp&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="50%" height="24px"&gt;&lt;STRONG&gt;Value&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="24px"&gt;2022-05-25 00:35&lt;/TD&gt;
&lt;TD width="50%" height="24px"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="24px"&gt;2022-05-25 00:36&lt;/TD&gt;
&lt;TD width="50%" height="24px"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="24px"&gt;2022-05-25 00:37&lt;/TD&gt;
&lt;TD width="50%" height="24px"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="24px"&gt;2022-05-25 00:38&lt;/TD&gt;
&lt;TD height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="24px"&gt;2022-05-25 00:48&lt;/TD&gt;
&lt;TD height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2022-05-25 00:58&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2022-05-25 01:01&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just using avg(Value) for hour 00 here results in 5 as the sum is divided by number of rows. But the intervals are irregular thus the last value (0) applies until next value (or until next hour). This issue obviously affects hourly averages and makes them incorrect. What I am in need of is some kind of time average, where time is taken into consideration.&lt;/P&gt;
&lt;P&gt;Any help or input would be very much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 10:03:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1935316#M77055</guid>
      <dc:creator>HillVi</dc:creator>
      <dc:date>2022-05-25T10:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Time Average - dealing with  irregular intervals</title>
      <link>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1935354#M77060</link>
      <description>&lt;P&gt;Normally, you could just use a weighted average by subtracting the end time from the start time. However, in this case, you don't actually have that information, as the "length" of a row is determined by the following row (if one exists), and there is nothing to tell us how long the last row is.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest having a look at this document: &lt;A href="https://community.qlik.com/t5/QlikView-Documents/Generating-Missing-Data-In-QlikView/ta-p/1491394" target="_blank"&gt;https://community.qlik.com/t5/QlikView-Documents/Generating-Missing-Data-In-QlikView/ta-p/1491394&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Specifically, pages 7 and 8 (how to populate a sparsely populated field) - doing so will create a scenario where each line refers to a single one-minute period and you can then use a straight average.&lt;/P&gt;
&lt;P&gt;If there's not practical, you could try calculating your own weighted average using something like (Below(Timestamp) - Timestamp) * Value&lt;/P&gt;
&lt;P&gt;But this would require some specific aggr() for the below() since you'd need to wrap this entire thing in a sum, and it would also require you handle the last row individually since there are no values below it.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 11:02:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1935354#M77060</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2022-05-25T11:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Time Average - dealing with  irregular intervals</title>
      <link>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1936275#M77146</link>
      <description>&lt;P&gt;maybe one solution could be to calculate and split intervals based on the next timestamp or full hour, e.g. like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;table1:
LOAD Timestamp(Timestamp,'YYYY-MM-DD hh:mm') as Timestamp,
     Value
Inline [
Timestamp,	Value
2022-05-25 00:35,	10
2022-05-25 00:36,	10
2022-05-25 00:37,	10
2022-05-25 00:38,	0
2022-05-25 00:48,	0
2022-05-25 00:58,	0
2022-05-25 01:01,	10
2022-05-25 01:10,	5
2022-05-25 01:50,	15
2022-05-25 02:30,	2
2022-05-25 02:55,	8
2022-05-25 03:15,	16
2022-05-25 04:00,	20
2022-05-25 08:10,	10
2022-05-25 12:30,	0
2022-05-25 14:50,	5
2022-05-25 14:59,	15
2022-05-25 15:00,	20
2022-05-25 15:01,	25
2022-05-25 15:50,	30
2022-05-25 23:30,	10
2022-05-26 05:00,	5
];

table2:
LOAD *,
     Timestamp(Timestamp#(Timestamp(Start,'YYYY-MM-DD hh'),'YYYY-MM-DD hh'),'YYYY-MM-DD hh:mm') as TimestampHour,
     Interval#(Interval(End-Start,'hh:mm'),'hh:mm') as Duration;
LOAD Timestamp,
     Value,
     Timestamp#(Timestamp(RangeMax(Start,Floor(Start,1/24)+(IterNo()-1)/24),'YYYY-MM-DD hh:mm'),'YYYY-MM-DD hh:mm')	as Start,
     Timestamp#(Timestamp(RangeMin(End,  Floor(Start,1/24)+ IterNo()   /24),'YYYY-MM-DD hh:mm'),'YYYY-MM-DD hh:mm')	as End
While Timestamp#(Timestamp(Floor(Start,1/24)+(IterNo()-1)/24,'YYYY-MM-DD hh:mm'),'YYYY-MM-DD hh:mm') &amp;lt; End;
LOAD *,
     Timestamp as Start,
     Alt(Previous(Timestamp),Timestamp) as End
Resident table1
Order By Timestamp desc;

DROP Table table1;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;your time weighted average then could be something like:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sum(Value*Duration)/Sum(Duration)&lt;/LI-CODE&gt;
&lt;P&gt;using TimestampHour as your dimension&lt;/P&gt;
&lt;P&gt;hope this helps&lt;/P&gt;
&lt;P&gt;Marco&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 21:26:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1936275#M77146</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2022-05-26T21:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Time Average - dealing with  irregular intervals</title>
      <link>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1940256#M77503</link>
      <description>&lt;P&gt;Thanks Marco and Or for you valuable input! I wouldn't have figured it out otherwise.&lt;/P&gt;
&lt;P&gt;It was quite testing and took a few hours, but I finally managed to overcome the issue by calculating based on duration/proportion of an hour.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 09:57:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Time-Average-dealing-with-irregular-intervals/m-p/1940256#M77503</guid>
      <dc:creator>HillVi</dc:creator>
      <dc:date>2022-06-07T09:57:29Z</dc:date>
    </item>
  </channel>
</rss>

