How to dynamically sort and rank rows using calculated fields
The example below can be found in the attached workbook, which uses the Sample Superstore data source.
Create a Calculated Field [LookupValue]
LAST()
This calculation returns the number of marks from the current position to the last mark in the partition. When Compute Using is set to Table Across, the rightmost column returns 0.
Create a Calculated Field [Across_Value]
WINDOW_SUM(IIF([LookupValue]=0,SUM([Sales]),0))
This calculation checks each column for the value of LAST(). If the result is 0, meaning it is the last column in the partition, it keeps that measure value; otherwise it returns 0. WINDOW_SUM() then sums across the row, so the last-column value is available across the partition.
Set Compute Using for [Across_Value] to Table Across.
Create a Calculated Field [Rank]
RANK([Across_Value])
This ranks each row based on the value from the rightmost column in the view.
Set Compute Using as follows:
[Rank] → Table Down[Across_Value] → Table Across[LookupValue] → Table AcrossThen place [Rank] on the worksheet as a discrete measure on the far left, and hide the header if needed.
001458323
1201 KB

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.