4 Replies Latest reply on Jun 10, 2017 9:13 PM by Kanupriya Dhiman

# Sorting by Difference of Calculated Field

Hi Experts

I am a beginner in using Tableau and I wanted to sort/rank the vehicle units(fender) by their sum of diiferences which have been calculated by week. For instance, fender a has a total of 700 till date from sum of diiferences as ranked 1, fender b as rank 2 and so on.

I have been struggling to rank them and have attached my workbook.

Appreciate if you could please have a look at the workbook under tab 'Sorting'.

Regards

Kanu

• ###### 1. Re: Sorting by Difference of Calculated Field

I didn't completely understand the requirement (and example of fender a,b when no such fenders exist), but hope this will help you.

• ###### 2. Re: Sorting by Difference of Calculated Field

Hi Kanupriya,

This might be a good opportunity to use the Rank() Calculation as a means of sorting.  Given that your weekly difference is already a table calculation, using more table calculation is best in this use case;  i created a few more to help with this rank/sort:

• [Weekly Difference] = ZN(SUM([Mileage])) - LOOKUP(ZN(SUM([Mileage])), -1)  //this is just your weekly difference calculation saved off so that it can be referenced (see: saving and customizing table calculations)
• [Sum of Weekly Difference]=WINDOW_SUM([Weekly Difference]) //Sum of the difference across all weeks for each vendor
• [Rank by Sum of Weekly Difference] = RANK([Sum of Weekly Difference]) //Ranking based off the prior sum.

I've attached the original workbook with the solution implemented.

• ###### 3. Re: Sorting by Difference of Calculated Field

HI Wilson

Appreciate your time on the same.

Regards

Kanu

• ###### 4. Re: Sorting by Difference of Calculated Field

Hi Hari

I was having a problem of ranking/sorting according to sum of differences across weeks which was a calculated field in itself. So sorting by sum would not be beneficial here.