# Qlik Sense App Development

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
New Contributor

## Sales of Top Rank Company

Rank Calculation

I have a data set like the below data set which has State wise Company Sales.

 State Company Sales A C1 500 B C1 600 C C1 4000 A C2 450 B C2 800 C C2 950 A C3 1000 B C3 2000 C C4 3500

The requirement is to find Rank 1 Company in State A,B,C in a pivot table.

The desired output is like.

 STATE Rank 1 Comapny Sales of Rank1 Company A C3 i.e. sales of C3 = 1000 B C3 i.e. sales of C3 = 2000 C C1 i.e. sales of C1 = 4000

8 Replies
MVP

## Re: Sales of Top Rank Company

Dimension 1: State

Dimension 2: Company

`Exp:If(rank(Sum(Sales))=1, Sum(Sales))`
New Contributor

## Re: Sales of Top Rank Company

In my case i have only State as dimension in pivot table so this expression will only return Sales for Rank 1 State. so this is not fulfilling the requirement

MVP

## Re: Sales of Top Rank Company

This?

`Aggr(If(rank(Sum(Sales))=1, Sum(Sales)),State,Company)`
Honored Contributor

Hi

PFA

Regards

Shivesh

New Contributor

## Re: Sales of Top Rank Company

please can you provide me the logic as i dont have qlikview to open this file.

Honored Contributor

## Re: Sales of Top Rank Company

Hi

PFB

Script:

T:

State, Company, Sales
A, C1, 500
B, C1, 600
C, C1, 4000
A, C2, 450
B, C2, 800
C, C2, 950
A, C3, 1000
B, C3, 2000
C, C4, 3500
];

Dimension : -State, Company

Expression : if(rank(Sales)=1,Company)

In presentation Tab, please hide Dimension Company

Honored Contributor

MVP

## Re: Sales of Top Rank Company

If you are interested in the name of the company try:

`FirstSortedValue(Company, -Aggr(sum(Sales), State, Company))`