<?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 Calculate time series in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Calculate-time-series/m-p/1917913#M75501</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;I'm developing a Qlik Sense app in which I want to calculate a time series starting from this table&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;ZMDM_DBL1:
LOAD * Inline [
ext_ui         , adat      , DC_EFF_EA          , DC_EFF_EI
IT002E9999991A , 04/04/2022, 05/04/2022 11:00:00, 05/04/2022 03:00:00
IT002E9999992A , 04/04/2022, 05/04/2022 11:00:00, 05/04/2022 17:00:00
IT002E9999993A , 04/04/2022, 05/04/2022 13:00:00, 05/04/2022 03:00:00
IT002E9999994A , 04/04/2022, 05/04/2022 16:00:00, 05/04/2022 17:00:00
IT002E9999991A , 05/04/2022, 06/04/2022 13:00:00, 06/04/2022 05:00:00
IT002E9999992A , 05/04/2022, 06/04/2022 14:00:00, 06/04/2022 18:00:00
IT002E9999993A , 05/04/2022, 06/04/2022 13:00:00, 06/04/2022 05:00:00
IT002E9999994A , 05/04/2022, 06/04/2022 14:00:00, 06/04/2022 18: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;&amp;nbsp;Dates are in the format DD/MM/YYYY and timestamps in the format&amp;nbsp;DD/MM/YYYY hh:mm:ss.&lt;/P&gt;
&lt;P&gt;Starting from this table I want to calculate an hourly time series that, after selecting a single 'adat', counts the number of 'ext_ui' that has both 'DC_EFF_EA' and 'DC_EFF_EI' less or equal of that hour in the time series.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Misure.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/77123iFB70A7022550749A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Misure.png" alt="Misure.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, selecting 'adat' = '04/04/2022' I want a time series starting from the next day at&amp;nbsp;05/04/2022 00:00:00 and finishing afeter 5 days at 10/04/2022 00:00:00 that counts&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 00:00:00 to&amp;nbsp;05/04/2022 10:00:00 --&amp;gt; 0 complete - 4 incomplete&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 11:00:00 to&amp;nbsp;05/04/2022 12:00:00 --&amp;gt; 1 (IT002E9999991A)&amp;nbsp;complete - 3 incomplete&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 13:00:00 to&amp;nbsp;05/04/2022 16:00:00 --&amp;gt; 2 (IT002E9999993A)&amp;nbsp;complete - 2 incomplete&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 17:00:00 to 10/04/2022 00:00:00 --&amp;gt; 4 (IT002E9999992A, IT002E9999994A)&amp;nbsp;complete - 0 incomplete&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried two ways (both working) but wants to know if there is a more efficient way.&lt;/P&gt;
&lt;P&gt;Starting from the creation of a calendar in the script:&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;// 1) Master calendar:
Temp: 
Load 
min(adat) as minDate,
max(adat) as maxDate
Resident ZMDM_DBL1;

Let vIntervalloMax = 120;
Let varMinDate = Num(Peek('minDate', 0, 'Temp')); 
Let varMaxDate = Num(Peek('maxDate', 0, 'Temp')); 
DROP Table Temp; 

TempCalendar:
LOAD 
Date($(varMinDate) + Iterno()-1) as adat,
Timestamp($(varMinDate) + (RecNo()-1)/24 + Iterno()) As AddedTimestamp
AUTOGENERATE $(vIntervalloMax)
While $(varMinDate) + IterNo()-1 &amp;lt;= $(varMaxDate);&lt;/LI-CODE&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;&lt;STRONG&gt;1- Dynamic - directly in FrontEnd graph&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I created a Time series Graph using:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dimension --&amp;gt; Group: AddedTimestamp&lt;/P&gt;
&lt;P&gt;Dimension --&amp;gt; Line:&amp;nbsp;&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;= IF(SubStringCount(
IF(not(isnull(DC_EFF_EA)) AND DC_EFF_EA &amp;lt;&amp;gt; '' AND DC_EFF_EA &amp;lt;= AddedTimestamp,'S_','N_') &amp;amp;
IF(not(isnull(DC_EFF_EI)) AND DC_EFF_EI &amp;lt;&amp;gt; '' AND DC_EFF_EI &amp;lt;= AddedTimestamp,'S_','N_')
, 'N') = 0,
'Complete','Incomplete')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Measure:&amp;nbsp;&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;count(ext_ui)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This solution works but takes long time to produce the graph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2 - Calculate the time series in the script&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To optimize the Front End graph, I tried to calculate the time series in the loading script:&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;LEFT JOIN (TempCalendar)
LOAD 
adat,
ext_ui,
DC_EFF_EA,
DC_EFF_EI
Resident ZMDM_DBL1;

MasterCalendar: 
Load 
  adat,
  AddedTimestamp,
count(
IF(SubStringCount(
IF(not(isnull(DC_EFF_EA)) AND DC_EFF_EA &amp;lt;&amp;gt; '' AND DC_EFF_EA &amp;lt;= AddedTimestamp,'S_','N_') &amp;amp;
IF(not(isnull(DC_EFF_EI)) AND DC_EFF_EI &amp;lt;&amp;gt; '' AND DC_EFF_EI &amp;lt;= AddedTimestamp,'S_','N_')
, 'N') = 0,
ext_ui
)) as Complete,
count(
IF(SubStringCount(
IF(not(isnull(DC_EFF_EA)) AND DC_EFF_EA &amp;lt;&amp;gt; '' AND DC_EFF_EA &amp;lt;= AddedTimestamp,'S_','N_') &amp;amp;
IF(not(isnull(DC_EFF_EI)) AND DC_EFF_EI &amp;lt;&amp;gt; '' AND DC_EFF_EI &amp;lt;= AddedTimestamp,'S_','N_')
, 'N') &amp;lt;&amp;gt; 0,
ext_ui
)) as Incomplete
Resident TempCalendar 
group by adat, AddedTimestamp
Order By adat ASC, AddedTimestamp ASC; 

Drop Table TempCalendar; &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This way takes a lot in the script but the front end is greatly enhanced. The problem that I see is the JOIN between TempCalendar (120 record for each 'adat') and ZMDM_DBL1 (about 800.000 records for each 'adat')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there another way to achive this result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Alessio&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2022 10:18:28 GMT</pubDate>
    <dc:creator>alessio_agrimi</dc:creator>
    <dc:date>2022-04-14T10:18:28Z</dc:date>
    <item>
      <title>Calculate time series</title>
      <link>https://community.qlik.com/t5/App-Development/Calculate-time-series/m-p/1917913#M75501</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;I'm developing a Qlik Sense app in which I want to calculate a time series starting from this table&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;ZMDM_DBL1:
LOAD * Inline [
ext_ui         , adat      , DC_EFF_EA          , DC_EFF_EI
IT002E9999991A , 04/04/2022, 05/04/2022 11:00:00, 05/04/2022 03:00:00
IT002E9999992A , 04/04/2022, 05/04/2022 11:00:00, 05/04/2022 17:00:00
IT002E9999993A , 04/04/2022, 05/04/2022 13:00:00, 05/04/2022 03:00:00
IT002E9999994A , 04/04/2022, 05/04/2022 16:00:00, 05/04/2022 17:00:00
IT002E9999991A , 05/04/2022, 06/04/2022 13:00:00, 06/04/2022 05:00:00
IT002E9999992A , 05/04/2022, 06/04/2022 14:00:00, 06/04/2022 18:00:00
IT002E9999993A , 05/04/2022, 06/04/2022 13:00:00, 06/04/2022 05:00:00
IT002E9999994A , 05/04/2022, 06/04/2022 14:00:00, 06/04/2022 18: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;&amp;nbsp;Dates are in the format DD/MM/YYYY and timestamps in the format&amp;nbsp;DD/MM/YYYY hh:mm:ss.&lt;/P&gt;
&lt;P&gt;Starting from this table I want to calculate an hourly time series that, after selecting a single 'adat', counts the number of 'ext_ui' that has both 'DC_EFF_EA' and 'DC_EFF_EI' less or equal of that hour in the time series.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Misure.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/77123iFB70A7022550749A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Misure.png" alt="Misure.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, selecting 'adat' = '04/04/2022' I want a time series starting from the next day at&amp;nbsp;05/04/2022 00:00:00 and finishing afeter 5 days at 10/04/2022 00:00:00 that counts&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 00:00:00 to&amp;nbsp;05/04/2022 10:00:00 --&amp;gt; 0 complete - 4 incomplete&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 11:00:00 to&amp;nbsp;05/04/2022 12:00:00 --&amp;gt; 1 (IT002E9999991A)&amp;nbsp;complete - 3 incomplete&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 13:00:00 to&amp;nbsp;05/04/2022 16:00:00 --&amp;gt; 2 (IT002E9999993A)&amp;nbsp;complete - 2 incomplete&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;05/04/2022 17:00:00 to 10/04/2022 00:00:00 --&amp;gt; 4 (IT002E9999992A, IT002E9999994A)&amp;nbsp;complete - 0 incomplete&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried two ways (both working) but wants to know if there is a more efficient way.&lt;/P&gt;
&lt;P&gt;Starting from the creation of a calendar in the script:&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;// 1) Master calendar:
Temp: 
Load 
min(adat) as minDate,
max(adat) as maxDate
Resident ZMDM_DBL1;

Let vIntervalloMax = 120;
Let varMinDate = Num(Peek('minDate', 0, 'Temp')); 
Let varMaxDate = Num(Peek('maxDate', 0, 'Temp')); 
DROP Table Temp; 

TempCalendar:
LOAD 
Date($(varMinDate) + Iterno()-1) as adat,
Timestamp($(varMinDate) + (RecNo()-1)/24 + Iterno()) As AddedTimestamp
AUTOGENERATE $(vIntervalloMax)
While $(varMinDate) + IterNo()-1 &amp;lt;= $(varMaxDate);&lt;/LI-CODE&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;&lt;STRONG&gt;1- Dynamic - directly in FrontEnd graph&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I created a Time series Graph using:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dimension --&amp;gt; Group: AddedTimestamp&lt;/P&gt;
&lt;P&gt;Dimension --&amp;gt; Line:&amp;nbsp;&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;= IF(SubStringCount(
IF(not(isnull(DC_EFF_EA)) AND DC_EFF_EA &amp;lt;&amp;gt; '' AND DC_EFF_EA &amp;lt;= AddedTimestamp,'S_','N_') &amp;amp;
IF(not(isnull(DC_EFF_EI)) AND DC_EFF_EI &amp;lt;&amp;gt; '' AND DC_EFF_EI &amp;lt;= AddedTimestamp,'S_','N_')
, 'N') = 0,
'Complete','Incomplete')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Measure:&amp;nbsp;&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;count(ext_ui)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This solution works but takes long time to produce the graph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2 - Calculate the time series in the script&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To optimize the Front End graph, I tried to calculate the time series in the loading script:&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;LEFT JOIN (TempCalendar)
LOAD 
adat,
ext_ui,
DC_EFF_EA,
DC_EFF_EI
Resident ZMDM_DBL1;

MasterCalendar: 
Load 
  adat,
  AddedTimestamp,
count(
IF(SubStringCount(
IF(not(isnull(DC_EFF_EA)) AND DC_EFF_EA &amp;lt;&amp;gt; '' AND DC_EFF_EA &amp;lt;= AddedTimestamp,'S_','N_') &amp;amp;
IF(not(isnull(DC_EFF_EI)) AND DC_EFF_EI &amp;lt;&amp;gt; '' AND DC_EFF_EI &amp;lt;= AddedTimestamp,'S_','N_')
, 'N') = 0,
ext_ui
)) as Complete,
count(
IF(SubStringCount(
IF(not(isnull(DC_EFF_EA)) AND DC_EFF_EA &amp;lt;&amp;gt; '' AND DC_EFF_EA &amp;lt;= AddedTimestamp,'S_','N_') &amp;amp;
IF(not(isnull(DC_EFF_EI)) AND DC_EFF_EI &amp;lt;&amp;gt; '' AND DC_EFF_EI &amp;lt;= AddedTimestamp,'S_','N_')
, 'N') &amp;lt;&amp;gt; 0,
ext_ui
)) as Incomplete
Resident TempCalendar 
group by adat, AddedTimestamp
Order By adat ASC, AddedTimestamp ASC; 

Drop Table TempCalendar; &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This way takes a lot in the script but the front end is greatly enhanced. The problem that I see is the JOIN between TempCalendar (120 record for each 'adat') and ZMDM_DBL1 (about 800.000 records for each 'adat')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there another way to achive this result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Alessio&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 10:18:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculate-time-series/m-p/1917913#M75501</guid>
      <dc:creator>alessio_agrimi</dc:creator>
      <dc:date>2022-04-14T10:18:28Z</dc:date>
    </item>
  </channel>
</rss>

