Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
mikael-c
Contributor III
Contributor III

Getting value from table based on group and max of 2 columns

Hello,

I'm quite new at qlik and I must say i'm having a hard time grasping how functions work.

I have a table consisting of 4 columns (see below). I'm trying to get the value, based on the group sector, where the columns date and time are the biggest (max).

sectordatetimevalue
s110118
s210120
s310123
s410124
s110219
s210221
s310223
s410223
s110321
s210323
s310324
s410322

 

This will be inserted into a text box and presented a little like this (results being the max for date and time, sorted by each group )

s1 = 21

s2 = 23

s3 = 24

s4 = 22


In SQL, I would do this either with a window function, with distinct on() or even with a sub-query, but no clue in qlik. Tried playing with aggr() and firstsortedvalue() but not sure where and how to put and order them in expressions.

Thank you!

1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

This should do it.  There may be an easier/cleaner way to do it but you can try this...

=concat(aggr( if(date= max(Total <sector> date) and time= max(Total <sector> time), sector & ' = ' & max(value)), sector, date, time), chr(13))

View solution in original post

2 Replies
stevejoyce
Specialist II
Specialist II

This should do it.  There may be an easier/cleaner way to do it but you can try this...

=concat(aggr( if(date= max(Total <sector> date) and time= max(Total <sector> time), sector & ' = ' & max(value)), sector, date, time), chr(13))

mikael-c
Contributor III
Contributor III
Author

This is great, thank you so much.
I have to play with this "Total <>" thing to get a hold of the concept.