7 Replies Latest reply on Oct 10, 2018 12:07 PM by Jim Dehner

# How to sort data based on an If statement?

Hi I am attaching a workbook where I need to sort my category based on average payment.

Average payment is based on an If function. i can't seem to have the option to sort my categories based on that function. any help is appreciated.

• ###### 1. Re: How to sort data based on an If statement?

Hi

One way is to use ranking functions

set up like this

returns this descending

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 2. Re: How to sort data based on an If statement?

Thanks Jim. when I created the ranking function, Tableau won't let me put it in front of the category in the rows. did you do any step after creating the function?

• ###### 3. Re: How to sort data based on an If statement?

You convert it to a discrete measure

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 4. Re: How to sort data based on an If statement?

Thanks Jim. see attached workbook. I created a rank function using Index. I like to sort the index function based on the average amount. I want to add amount, average amount and still sort descending using the average amount (which is an If FUNCTION)

Your way didn't work well as I think it's selecting unique ranking by each year.. does it make sense?

• ###### 5. Re: How to sort data based on an If statement?

Tony

see the attached

Index() just is a number of rows and not what you want to rank on - you are out here enough to know that

this is the formula that will rank on your avg payments

it will return this

jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 6. Re: How to sort data based on an If statement?

Hi Jim. see attached workbook. I was able to rank based on index. i can't sort on average amount because its an IF function. I want to be able to add average amount, amount and sort descending based on average amount. i have million of rows if my data.

your function created a Null ranking and it grouped multiple categories into the same ranks. hope i am making sense here

• ###### 7. Re: How to sort data based on an If statement?

I didn't have that problem -