Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Firstsortedvalue question.

I am trying to find out city for which I have maximum Applications. Each application has a unique id : AppId. My expression returns null.


Expression:

vFirstCity=FirstSortedValue (City,Aggr(Count(AppId),City ))

Tags (2)
1 Solution

Accepted Solutions
Highlighted
MVP
MVP

Re: Firstsortedvalue question.

For max you will need a negative sign next to the Aggr function:

vFirstCity=FirstSortedValue(City, -Aggr(Count(AppId), City))

7 Replies
Highlighted
MVP
MVP

Re: Firstsortedvalue question.

For max you will need a negative sign next to the Aggr function:

vFirstCity=FirstSortedValue(City, -Aggr(Count(AppId), City))

Not applicable

Re: Firstsortedvalue question.

Thanks a lot for quick revert.Extremely silly mistake.Anyway to get any value if there are multiple cities with same count ?

neetha_p
Honored Contributor

Re: Firstsortedvalue question.

Hi,

Yes for Maximum value,minus sign should be used.

vFirstCity=FirstSortedValue(City, -Aggr(Count(AppId), City))


if you get multiple values then FirstSortedValue() will return null.


MVP
MVP

Re: Firstsortedvalue question.

You can use a Concat() function to see them all:

=Concat(Aggr(FirstSortedValue(City, -Aggr(Count(AppId), City)), City), ', ')

neetha_p
Honored Contributor

Re: Firstsortedvalue question.

Hi,

Here is an extract from the Reference Manual. Hope this helps.

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

returns the first value of expression sorted by corresponding sortweight

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, you will

get the nth value in order. If the word distinct occurs before the

expression, all duplicates will be disregarded.

Employee
Employee

Re: Firstsortedvalue question.

You can choose a second criteria, dividing by a large number

FirstSortedValue(City, -Aggr(Count(AppId), City) + count(otherfield)/10000 )

Not applicable

Re: Firstsortedvalue question.

That makes sense. Thanks.

Community Browser