Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
ARe
Partner - Contributor II
Partner - Contributor II

Aggregation and grouping by multiple fields in load script

Hi Community,

I'm experiencing troubles in my load script.

I want to find the newest value from a table (with regards to a specific PatientID and VariableID).

As a test I did this:

 

 

 

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;

 

 

 

It gives me the expected results namely

1,A,30.08.2022,70

1,A,31.08.2022,50

 

Then I tried the same principle on existing data from the database:

 

 

 

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;

 

 

 

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.

ARe_0-1662993079387.png

 

What am I doing wrong?

Thanks!

BR Andreas

 

PS: QVD file:

ARe_0-1662993578365.png

 

 

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

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.

- Marcus

View solution in original post

6 Replies
marcus_sommer

I think it's caused from grouping for a date but querying a timestamp within the firstsortedvalue().

- Marcus

JHuis
Creator III
Creator III

 

Like this:

 

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, MaxString(ValueTime) as 'Wert',
Max(NumValue) as NumValue
resident test
group by PatientID, VariableID, Bilanztag;

drop table test

ARe
Partner - Contributor II
Partner - Contributor II
Author

Hi JHus,

unfortunately that doesn't solve my problem because it returns the max of a time and max of NumValue.

I'm looking for the latest entry (where NumValue could also be a lower number).

Thanks anyways!

BR,

Andreas

ARe
Partner - Contributor II
Partner - Contributor II
Author

Hi Marcus,

are you suggesting to convert "everything" to string before grouping / using firstsortedvalue?

BR,

Andreas

marcus_sommer

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.

- Marcus

ARe
Partner - Contributor II
Partner - Contributor II
Author

Hi

you are right - Bilanztag is a timestamp:

ARe_0-1663078474497.png

 

I now changed the way that field is created

OLD:
if(frac(ValueTime)<time(1/4),date(ValueTime-1),date(ValueTime)) as 'Bilanztag'

NEW:
if(frac(ValueTime)<time(1/4),date(floor(ValueTime)-1),date(floor(ValueTime))) as 'Bilanztag'

 

-->

ARe_1-1663078778113.png

 

Now the firstsortedvalue() is working as expected.

Thanks a lot!

BR,

Andreas