Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
manojkulkarni
Partner - Specialist II
Partner - Specialist II

Get Maximum record

Hi All,

How to get the maximum record data from the given list in the script ? Below is the sample data and expected result.

Sample Data:

variabletimestmpvalueDate
5315354047100:02:311025-05-2021
5315354105100:02:311425-05-2021
5315354047100:06:071525-05-2021
5315354105100:06:07925-05-2021
5315354047100:11:062525-05-2021
5315354105100:11:0612025-05-2021
5315354047100:16:06025-05-2021
5315354105100:16:061125-05-2021

 

Expected Result:

variabletimestmpvalueDate
5315354105100:02:311425-05-2021
5315354047100:06:071525-05-2021
5315354105100:11:0612025-05-2021
5315354105100:16:061125-05-2021
1 Solution

Accepted Solutions
JuanGerardo
Partner - Specialist
Partner - Specialist

OK, I see the mistake. You have to use -value instead of value in the firstsortedvalue:

Data:
Load * Inline [
variable	timestmp	value	Date
53153540471	00:02:31	10	25-05-2021
53153541051	00:02:31	14	25-05-2021
53153540471	00:06:07	15	25-05-2021
53153541051	00:06:07	9	25-05-2021
53153540471	00:11:06	25	25-05-2021
53153541051	00:11:06	120	25-05-2021
53153540471	00:16:06	0	25-05-2021
53153541051	00:16:06	11	25-05-2021
] (delimiter is '\t');

DataMax:
NoConcatenate
Load
    FirstSortedValue(variable, -value)	AS variable,
    Date,
    timestmp,
    Max(value)	AS value
Resident Data
Group By
    Date,
    timestmp
;

Drop Table Data;

JG

View solution in original post

3 Replies
JuanGerardo
Partner - Specialist
Partner - Specialist

Hi @manojkulkarni, I suggest to use the Max and FirstSortedValue functions for aggregating that table:

Data:
Load * Inline [
variable	timestmp	value	Date
53153540471	00:02:31	10	25-05-2021
53153541051	00:02:31	14	25-05-2021
53153540471	00:06:07	15	25-05-2021
53153541051	00:06:07	9	25-05-2021
53153540471	00:11:06	25	25-05-2021
53153541051	00:11:06	120	25-05-2021
53153540471	00:16:06	0	25-05-2021
53153541051	00:16:06	11	25-05-2021
] (delimiter is '\t');

DataMax:
NoConcatenate
Load
    FirstSortedValue(variable, value)	AS variable,
    Date,
    timestmp,
    Max(value)	AS value
Resident Data
Group By
    Date,
    timestmp
;

Drop Table Data;

JG

manojkulkarni
Partner - Specialist II
Partner - Specialist II
Author

Thanks for your Quick reply. Above script is not returning the expected result

JuanGerardo
Partner - Specialist
Partner - Specialist

OK, I see the mistake. You have to use -value instead of value in the firstsortedvalue:

Data:
Load * Inline [
variable	timestmp	value	Date
53153540471	00:02:31	10	25-05-2021
53153541051	00:02:31	14	25-05-2021
53153540471	00:06:07	15	25-05-2021
53153541051	00:06:07	9	25-05-2021
53153540471	00:11:06	25	25-05-2021
53153541051	00:11:06	120	25-05-2021
53153540471	00:16:06	0	25-05-2021
53153541051	00:16:06	11	25-05-2021
] (delimiter is '\t');

DataMax:
NoConcatenate
Load
    FirstSortedValue(variable, -value)	AS variable,
    Date,
    timestmp,
    Max(value)	AS value
Resident Data
Group By
    Date,
    timestmp
;

Drop Table Data;

JG