<?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: Could this  data loading script be improved to provide accurate end results? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546066#M1334728</link>
    <description>&lt;P&gt;Then go with the mentioned logic to get a start + end field with a conditional approach like the ChangeFlag - just keep attention on the sort order to sort the timestamp descending.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Apr 2026 14:19:59 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2026-04-02T14:19:59Z</dc:date>
    <item>
      <title>Could this  data loading script be improved to provide accurate end results?</title>
      <link>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546042#M1334723</link>
      <description>&lt;P&gt;Hi, a code review would be highly appreciated.&lt;/P&gt;&lt;P&gt;This was generated by ChatGPT and it doesn't work correct. EndTime and consequently DurationMin (duration in minutes)&amp;nbsp; are not correctly calculated.&lt;/P&gt;&lt;DIV&gt;RawData:&lt;/DIV&gt;&lt;DIV&gt;load&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Timestamp#(DateTime, 'DD.MM.YYYY hh:mm') as tmpDateTime,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; [Work Center],&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; MachineStatusID&lt;/DIV&gt;&lt;DIV&gt;from MachineStatuses.xlsx (ooxml, embedded labels, table is Sheet1);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;WithFlags:&lt;/DIV&gt;&lt;DIV&gt;load&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; *,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; If([Work Center] = Peek('Work Center') and&amp;nbsp; MachineStatusID = Peek('MachineStatusID'), 0, 1) as ChangeFlag&lt;/DIV&gt;&lt;DIV&gt;resident RawData&lt;/DIV&gt;&lt;DIV&gt;order By [Work Center], MachineStatusID,&amp;nbsp; tmpDateTime;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;drop table RawData;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;WithGroups:&lt;/DIV&gt;&lt;DIV&gt;load&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; *,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; rangesum(Peek('GroupID'), ChangeFlag) as GroupID&lt;/DIV&gt;&lt;DIV&gt;resident WithFlags&lt;/DIV&gt;&lt;DIV&gt;order by [Work Center], MachineStatusID, tmpDateTime;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MachineStatusesDuration:&lt;/DIV&gt;&lt;DIV&gt;load&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; [Work Center],&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; MachineStatusID,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; GroupID,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; min(tmpDateTime) as StartTime,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; max(tmpDateTime) as EndTime,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; interval(max(tmpDateTime) - min(tmpDateTime), 'hh:mm:ss') * 1440&amp;nbsp; as DurationMin&lt;/DIV&gt;&lt;DIV&gt;resident WithGroups&lt;/DIV&gt;&lt;DIV&gt;group by [Work Center], MachineStatusID, GroupID;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;drop tables WithFlags, WithGroups;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2026 12:14:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546042#M1334723</guid>
      <dc:creator>NenadV</dc:creator>
      <dc:date>2026-04-02T12:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Could this  data loading script be improved to provide accurate end results?</title>
      <link>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546047#M1334724</link>
      <description>&lt;P&gt;I assume that you want to calculate the duration between the timestamps of the Work Center. The approach to create the GroupID and to aggregate the timestamps against it may in general a working one but it would require to remove the MachineStatusID from the aggregation.&lt;/P&gt;&lt;P&gt;Personally I wouldn't do it in this way else using the interrecord-functions of peek() and previous() to create from the timestamp directly two fields - start + end. Means similar like the method by the ChangeFlag the previous timestamp is used as end and the current value as start - you need only to sort the timestamp with desc.&lt;/P&gt;&lt;P&gt;Depending on the goal it might be useful to repeat the logic in asc and desc and with the filtering against certain states respectively their changes.&lt;/P&gt;&lt;P&gt;Don't try everything at one else doing it in n small steps with a limited data-set shows very quickly if start and end information are the wanted ones and what happens if the order- and/or the if-conditions are a bit adjusted. Further helpful would be to add recno() + rowno() to the loads to track the way from the source to the target.&lt;/P&gt;&lt;P&gt;On top of such measurements may come some aggregations to get the min/max/count values against n unknown records of Work Center and states.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2026 12:57:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546047#M1334724</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2026-04-02T12:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Could this  data loading script be improved to provide accurate end results?</title>
      <link>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546049#M1334725</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/28038"&gt;@marcus_sommer&lt;/a&gt;&amp;nbsp; I need to calculate duration for each work center and machineStatus.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2026 13:08:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546049#M1334725</guid>
      <dc:creator>NenadV</dc:creator>
      <dc:date>2026-04-02T13:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Could this  data loading script be improved to provide accurate end results?</title>
      <link>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546066#M1334728</link>
      <description>&lt;P&gt;Then go with the mentioned logic to get a start + end field with a conditional approach like the ChangeFlag - just keep attention on the sort order to sort the timestamp descending.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2026 14:19:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546066#M1334728</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2026-04-02T14:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Could this  data loading script be improved to provide accurate end results?</title>
      <link>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546125#M1334738</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/28038"&gt;@marcus_sommer&lt;/a&gt;&amp;nbsp;FYI ChatGPT has helped me to get what I need using this a little reworked data loading script:&lt;/P&gt;&lt;P&gt;SortedData:&lt;BR /&gt;LOAD&lt;BR /&gt;&amp;nbsp;[Work Center],&lt;BR /&gt;&amp;nbsp;MachineStatusID,&lt;BR /&gt;&amp;nbsp;DateTime as StartDateTime&lt;BR /&gt;from [..\ConsolidatedExcel\MachineStatuses.xlsx] (ooxml, embedded labels, table is Sheet1)&lt;BR /&gt;ORDER BY [Work Center], MachineStatusID, DateTime; // this is not correct syntax so I had to re- work it&amp;nbsp; &amp;nbsp;little&amp;nbsp; by using one temporary table and apply order by in a load . . . resident statement&lt;/P&gt;&lt;P&gt;FinalData:&lt;BR /&gt;LOAD&lt;BR /&gt;[Work Center],&lt;BR /&gt;MachineStatusID,&lt;BR /&gt;StartDateTime,&lt;BR /&gt;If(&lt;BR /&gt;[Work Center] = Peek([Work Center]) and MachineStatusID = Peek(MachineStatusID),&lt;BR /&gt;Peek(StartDateTime)&lt;BR /&gt;) as EndDateTime,&lt;BR /&gt;If(&lt;BR /&gt;[Work Center] = Peek([Work Center]) and MachineStatusID = Peek(MachineStatusID),&lt;BR /&gt;(Peek(StartDateTime) - StartDateTime) * 1440&lt;BR /&gt;) as DurationMinutes&lt;BR /&gt;RESIDENT SortedData&lt;BR /&gt;ORDER BY [Work Center], MachineStatusID, StartDateTime DESC;&lt;/P&gt;&lt;P&gt;DROP TABLE SortedData;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2026 13:30:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Could-this-data-loading-script-be-improved-to-provide-accurate/m-p/2546125#M1334738</guid>
      <dc:creator>NenadV</dc:creator>
      <dc:date>2026-04-03T13:30:42Z</dc:date>
    </item>
  </channel>
</rss>

