Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
jduluc12
Creator
Creator

FirstSortedValue with same value

Hi,

Is it possible to make FirstSortedValue return values when the sorting field has same values?

For example:

if the data looks like

IDvalue
110
210
38
47
56

If I do

FirstSortedValue(Distinct ID, -value) then i get 1

But what if I want to get ID 2?

Can I do something thing like

FirstSortedValue(Distinct ID, -value, 2)

I tried but it does not work.

any suggestions?

Thanks!

3 Replies
neelamsaroha157
Specialist II
Specialist II

Try this -

FirstSortedValue(Distinct ID, value)

jduluc12
Creator
Creator
Author

No it does work.

It brings the ID of the lowest value.

What i need is to get the second ID with highest value.

vishsaggi
Champion III
Champion III

Not sure if this is a good way of doing it but you can try below options:

Option1:

=Firstsortedvalue(Aggr(Max(ID), value), Aggr(Max(value, -2), value))

Option2: Tweak in the script like:

Ranking:

LOAD *, Autonumber(ID, value) AS IDRank;

LOAD ID,

     value

FROM

[https://community.qlik.com/thread/314058]

(html, codepage is 1252, embedded labels, table is @1);

Add straight table chart with

Dim:

value

Expr:

= Firstsortedvalue(ID, -Aggr(IDRank, ID))