Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

FirstSortValue

hello frnds,

can any one explain me what is FirstSortValue() and where we can use it.

with an example

please

5 Replies
Anonymous
Not applicable
Author

Hi

watch this video it explains about all your doubts

QlikView | Expressions | AGGR Function with Max and FirstSortedValue function - YouTube

Regards

Harsha

Not applicable
Author

it will give the first value of expression based on the sort wait ,sort wait should be numeric

date and sales u have fields

date:

1/1/2014

2/1/2014

3/1/2014

4/1/2014

5/1/2014

sales:

100

200

300

600

500

here u want see the top value and bottom value

firstsortedvalue(date,-sales)  in chart if u written then it gives top value

firstsortedvalue(date,sales) in chart if u written then it gives bottom value

arulsettu
Master III
Master III

check this

FirstSortedValue()

Not applicable
Author

Hello Rahim,

here you go

Firstsortedvalue()
This function returns the first value of the expression sorted by corresponding sort-weight when the expression is executed over a number of records as defined by a group by clause. Sort-weight returns a numeric value where the lowest value will render the corresponding value of the expression to be sorted first.
Syntax
firstsortedvalue ([ distinct ] expression [, sort-weight [, n ]])

Let us take a scenario, where we have to identify Product Name that sold the most during selected period by company. To do so, we have to use AGGR function in conjunction with function FIRSTSORTEDVALUE().

FIRSTSORTEDVALUE function return the first value of expression sorted by corresponding sort-weight. Sort weight should be numeric value and it returns NULL value if more than one expression value share the same sort order so if there is tie in sorting it returns NULL value unless you do some thing else to overcome this issue.

To extract the last sorted value which is opposite to first sorted value, we need to add a minus sign (-) to sort weight expression. We can also use set analysis and Total in FIRSTSORTEDVALUE function.

Syntax:- FIRSTSORTVALUE( Field, Sort-Weight)

AGGR_FIRSTSORTEDVALUE_Qlikview

As mentioned above, to identify name of Product based on highest sales product by company, we have to write expression like :

=FIRSTSORTEDVALUE (Product, – aggr(sum(Sale),Company_Name,Product) )

In above expression, AGGR statement generates a virtual table that has total sales by company and product. Then, FIRSTSORTEDVALUE function identifies the Product Name from the virtual table for highest sale. Because aggr function is preceded by minus sign (-), it will return product name against highest sales.

tyagishaila
Specialist
Specialist

Hello Rahim,


You can use FirstSortedValue both in the script and user interface (UI) of QlikView.

FirstSortedValue works when loading aggregated (grouped) data

Here we have a simple table showing when a customer bought a particular product:

QlikView FirstSortedValue

Loading the data grouped by Customer we can use the DayOfSale as the sort-weight, position 1 and return the value of product.

Customer:
Load
            Customer
            ,FirstSortedValue(Product,DayOfSale,1) as FirstProductBought
Resident Customers_Temp
Group by Customer

QlikView FirstSortedValue