Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Straight table-aggr function

Hi Below is my source table

CallIDIDNameContact No
8467A1Jeff1234567890
3456A1Jeff1234567890
6789A1Jeff1234567890
1232A1Jeff2345678901
3234A1Jeff2345678901
5453A1Jeff5678901234
7865A2Lynn4567890123
5463A2Lynn4567890123
9876A2Lynn4567890123
7656A2Lynn8901234567
8329A2Lynn8901234567
7754A2Lynn3456789012
1234A3Mark7890123456
5434A3Mark7890123456
6767A3Mark7890123456
5644A3Mark9012345678
7621A3Mark9012345678
6750A3Mark6789012345

I need to create a straight table with top 3 contact numbers for each combination if ID and Name based on count of CallID

Example if I select Name as Jeff

IDName123
A1Jeff123456789023456789015678901234

I'm using following expressions

=

if(aggr(rank(Count(CallID))=1,ID,Name,[Contact No])=-1,[Contact No])

=

if(aggr(rank(Count(CallID))=2,ID,Name,[Contact No])=-1,[Contact No])

=

if(aggr(rank(Count(CallID))=3,ID,Name,[Contact No])=-0,[Contact No])

But my final result is currently blank

Attaching source data and qv application.

1 Solution

Accepted Solutions
anbu1984
Master III
Master III

5 Replies
giakoum
Partner - Master II
Partner - Master II

you need the following function. Note that you need it 3 times, with n=1 2 or 3 to get the 3 values and count(CallID) as sort weight

firstsortedvalue ([ distinct ] expression [, sort-weight [, n ]])

Returns the first value of expression sorted by corresponding sort-weight when expression is iterated over a number of records as defined by a group by clause. Sort-weight should return a numeric value where the lowest value will render the corresponding value of expression to be sorted first. By preceding the sort-value expression with a minus sign, the function will return the last value instead. If more than one value of expression share the same lowest sort-order, the function will return NULL. By stating an n larger than 1, the nth value in order will be returned. If the word distinct occurs before the expression, all duplicates will be disregarded.

Example:

Load Customer,

firstsortedvalue(PurchasedArticle, OrderDate) as FirstProductBought from abc.csv

group by Customer;

Not applicable
Author


I tried adding above expression but it returns null value

=

FIRSTSORTEDVALUE(aggr([Contact No],ID,Name),Count(CallID),1)

=

FIRSTSORTEDVALUE(aggr([Contact No],ID,Name),Count(CallID),2)

=

FIRSTSORTEDVALUE(aggr([Contact No],ID,Name),Count(CallID

),3)

giakoum
Partner - Master II
Partner - Master II

I think that Count(CallID) cannot be used as sort weight.

Try calculating it in the reload script as a new field

anbu1984
Master III
Master III

Check this

Not applicable
Author

Thanks a lot Anbu it worked...