<?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: Aggregation and grouping by multiple fields in load script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980378#M80906</link>
    <description>&lt;P&gt;Hi Marcus,&lt;/P&gt;
&lt;P&gt;are you suggesting to convert "everything" to string before grouping / using firstsortedvalue?&lt;/P&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Andreas&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 12:45:39 GMT</pubDate>
    <dc:creator>ARe</dc:creator>
    <dc:date>2022-09-13T12:45:39Z</dc:date>
    <item>
      <title>Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1979909#M80874</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;
&lt;P&gt;I'm experiencing troubles in my load script.&lt;/P&gt;
&lt;P&gt;I want to find the newest value from a table (with regards to a specific PatientID and VariableID).&lt;/P&gt;
&lt;P&gt;As a test I did this:&lt;/P&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;LI-CODE lang="php"&gt;SET DateFormat='DD.MM.YYYY';
SET TimestampFormat='DD.MM.YYYY hh:mm:ss[.fff]';

[test]:
load * inline [
VariableID, PatientID, ValueTime, NumValue, Bilanztag
1,A,'31.08.2022 14:03:09', 50, '31.08.2022'
1,A,'31.08.2022 14:13:09', 50, '31.08.2022'
1,A,'31.08.2022 14:23:09', 50, '31.08.2022'
1,A,'30.08.2022 14:23:09', 70, '30.08.2022'

];

[Test2]:
load PatientID, VariableID, Bilanztag, FirstSortedValue(distinct NumValue,-ValueTime) as 'Wert'
resident test
group by PatientID, VariableID, Bilanztag;&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;It gives me the expected results namely&lt;/P&gt;
&lt;P&gt;1,A,30.08.2022,70&lt;/P&gt;
&lt;P&gt;1,A,31.08.2022,50&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I tried the same principle on existing data from the database:&lt;/P&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;LI-CODE lang="php"&gt;SET DateFormat='DD.MM.YYYY';
SET TimestampFormat='DD.MM.YYYY hh:mm:ss[.fff]';
[DerValsFull]:
load PatientID, VariableID, Bilanztag, FirstSortedValue(distinct NumValue,-ValueTime) as 'Wert'
from [lib://QVDSource_CCC_KFN/1ME_ERI_DerVals.qvd] (qvd)
group by PatientID, VariableID, Bilanztag;&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;Here the result is unexpected. I'm getting more or less the raw data from the QVD. The aggregation over PatientID, VariableID, Bilanztag is completely ignored.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ARe_0-1662993079387.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/88910i193B08BEA69D197D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ARe_0-1662993079387.png" alt="ARe_0-1662993079387.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I doing wrong?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;BR Andreas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: QVD file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ARe_0-1662993578365.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/88912i37B0FE6F86E280B7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ARe_0-1662993578365.png" alt="ARe_0-1662993578365.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 14:39:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1979909#M80874</guid>
      <dc:creator>ARe</dc:creator>
      <dc:date>2022-09-12T14:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980319#M80898</link>
      <description>&lt;P&gt;I think it's caused from grouping for a date but querying a timestamp within the firstsortedvalue().&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 11:01:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980319#M80898</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-09-13T11:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980334#M80899</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SET DateFormat='DD.MM.YYYY';&lt;BR /&gt;SET TimestampFormat='DD.MM.YYYY hh:mm:ss[.fff]';&lt;/P&gt;
&lt;P&gt;[test]:&lt;BR /&gt;load * inline [&lt;BR /&gt;VariableID, PatientID, ValueTime, NumValue, Bilanztag&lt;BR /&gt;1,A,'31.08.2022 14:03:09', 50, '31.08.2022'&lt;BR /&gt;1,A,'31.08.2022 14:13:09', 50, '31.08.2022'&lt;BR /&gt;1,A,'31.08.2022 14:23:09', 50, '31.08.2022'&lt;BR /&gt;1,A,'30.08.2022 14:23:09', 70, '30.08.2022'&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;[Test2]:&lt;BR /&gt;load PatientID, VariableID, Bilanztag, MaxString(ValueTime) as 'Wert',&lt;BR /&gt;Max(NumValue) as NumValue&lt;BR /&gt;resident test&lt;BR /&gt;group by PatientID, VariableID, Bilanztag;&lt;/P&gt;
&lt;P&gt;drop table test&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 11:42:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980334#M80899</guid>
      <dc:creator>JHuis</dc:creator>
      <dc:date>2022-09-13T11:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980376#M80905</link>
      <description>&lt;P&gt;Hi JHus,&lt;/P&gt;
&lt;P&gt;unfortunately that doesn't solve my problem because it returns the max of a time and max of NumValue.&lt;/P&gt;
&lt;P&gt;I'm looking for the latest entry (where NumValue could also be a lower number).&lt;/P&gt;
&lt;P&gt;Thanks anyways!&lt;/P&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Andreas&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:44:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980376#M80905</guid>
      <dc:creator>ARe</dc:creator>
      <dc:date>2022-09-13T12:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980378#M80906</link>
      <description>&lt;P&gt;Hi Marcus,&lt;/P&gt;
&lt;P&gt;are you suggesting to convert "everything" to string before grouping / using firstsortedvalue?&lt;/P&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Andreas&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:45:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980378#M80906</guid>
      <dc:creator>ARe</dc:creator>
      <dc:date>2022-09-13T12:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980447#M80914</link>
      <description>&lt;P&gt;No, rather the opposite would be true. Take a look if ValueTime and Bilanztag are really numeric and that Bilanztag is a date and not a timestamp. Just load both fields additionally with num(). If the result is NULL the values aren't regarded as numbers and if Bilanztag didn't returned an integer else a float it's a timestamp.&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 13:56:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980447#M80914</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-09-13T13:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation and grouping by multiple fields in load script</title>
      <link>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980479#M80917</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;you are right - Bilanztag is a timestamp:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ARe_0-1663078474497.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/89014i66845703A4668459/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ARe_0-1663078474497.png" alt="ARe_0-1663078474497.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I now changed the way that field is created&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;OLD:
if(frac(ValueTime)&amp;lt;time(1/4),date(ValueTime-1),date(ValueTime)) as 'Bilanztag'

NEW:
if(frac(ValueTime)&amp;lt;time(1/4),date(floor(ValueTime)-1),date(floor(ValueTime))) as 'Bilanztag'&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;--&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ARe_1-1663078778113.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/89016i922D129F366E74A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ARe_1-1663078778113.png" alt="ARe_1-1663078778113.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the firstsortedvalue() is working as expected.&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Andreas&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:19:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Aggregation-and-grouping-by-multiple-fields-in-load-script/m-p/1980479#M80917</guid>
      <dc:creator>ARe</dc:creator>
      <dc:date>2022-09-13T14:19:44Z</dc:date>
    </item>
  </channel>
</rss>

