KNOWLEDGE BASE

## Dynamically Ranking Measures by Most Recent Data

Published: 20 Jan 2015

### Question

How to dynamically sort and rank measures by creating calculated fields.

### Environment

Tableau Desktop

The below example can be found in the attached workbook, which uses the example data source Superstore.
1. Create a Calculated Field [LookupValue]

LAST()

What this does is Index the columns, so that the far most right column is always 0

2. Create a Calculated Field [Across_Value]

WINDOW_SUM(IIF([LookupValue]=0,([Value]),0))

What this does, is check each column for the value of LAST(). If it is 0 (The last column), then we sum the Measure amount, else, we have 0.

3. Create a Calculated Field [Rank]

RANK([Across_Value])

What this does is Rank the SUM of the right most column in Tableau.

For the COMPUTE USING for RANK

Rank > Table Down
Across_Value > Table Across
Lookup > Month Then place the [Rank] field on the worksheet to the far most left as a discrete measure, and hide the header.
{"ft_lang_label":"__label__en","ft_lang_prob":0.73030627,"math_prob":0.9471171,"size":1087,"snap":"2020-34-2020-40","text_gpt3_token_len":254,"char_repetition_ratio":0.108956605,"word_repetition_ratio":0.011560693,"special_character_ratio":0.22539099,"punctuation_ratio":0.096938774,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9932082,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-10T03:08:47Z\",\"WARC-Record-ID\":\"<urn:uuid:2d0fe170-a9c0-472d-9594-e15912c6bee9>\",\"Content-Length\":\"47022\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:88182d48-eee3-42e4-af8d-5ebe701d5c58>\",\"WARC-Concurrent-To\":\"<urn:uuid:cd1477e7-4b32-4425-a9db-fb89561d1515>\",\"WARC-IP-Address\":\"13.109.206.9\",\"WARC-Target-URI\":\"https://kb.tableau.com/articles/howto/dynamically-ranking-measures-by-most-recent-data\",\"WARC-Payload-Digest\":\"sha1:SAO5ZOVRV3DDDTH5Y3FTEL6S64IUJE5P\",\"WARC-Block-Digest\":\"sha1:RPW44FSUJK7UHT6LZEF2IIXBI6TCQOUP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439738603.37_warc_CC-MAIN-20200810012015-20200810042015-00306.warc.gz\"}"}