Creating a Formula Field to Sort Records in True Alphabetical Order
Frequently, many users experience frustration when attempting to sort data to their exact specifications. These frustrations often occur because the data entered into Salesforce differs from the type of sort desired by the user. An example of this situation could occur if you wanted to track your DVD collection and sort through the albums alphabetically. For instance, if my DVD collection includes the shows Arrested Development, The Office, and The New Adventures of Old Christine, it would not benefit me to search through all of my DVD’s that begin with the word ‘The’ because my alphabetical sort will recognize the word ‘The’ in quest to alphabetize my DVD collection. As a result, the following formula field explains how a user can sort through their data in true alphabetical order.
- Select a text-based formula field
- Choose to create an advanced formula
- Develop an IF/THEN logic statement to define your sort.
- In this case, IF a DVD begins with the word ‘The’, then I want to do an alphabetical sort that ignores the word ‘The’.
- Select the IF function from the function box on the right side of the create an advanced formula screen.
- Add an open parentheses, type the word ‘BEGINS’, add an open parentheses and quotes around the text to be ignored and close the parentheses.
- In this case, the formula should read IF(BEGINS(Name, “The”),
- Now select the MID function in the function box on the right side of the screen to indicate the new starting position of your sort. The starting position will correlate with the number of characters contained in the text you want to ignore.
- In this example, the word “The” is 3 characters, but a space will come before the next word, which means we want to ignore the first 4 characters.
- After selecting the MID function, add an open parentheses, type Name, add a comma, type the number of characters to be ignored, add another comma, select the maximum amount of characters in your text field and close the parentheses.
- The above formula would now read IF(BEGINS(Name, “The”), MID(Name, 4, 251)
- If the only word to be ignored is the word “The”, you must add the following text to complete the formula: ,Name)
- If you have other parameters to include in your sort, you must specify the amount of characters to be ignored.
- For example, if you own the DVD “The New Adventures of Old Christine”, you might want the alphabetical sort to find this record by the word ‘Christine’. In this situation, you must add a formula that would read IF(BEGINS(Name,”The New Adventures of Old”, MID(Name, 26, 229). Now we have created a formula to ignore the first 26 characters of text, which will enable the sort to only recognize the word Christine.
Our two rules would be entered into a custom formula as the following: IF(BEGINS(Name, “The New Adventures of Old”), MID(Name,26,229) ,IF(BEGINS(Name, “The”), MID(Name,4,251) , Name))
Other information to know: When creating multiple rules to sort data, the longest rules must be entered first and followed by rules to ignore fewer characters. Additionally, you must add a closed parentheses to end of the formula for each custom rule you have created.
In summary, developing a custom formula field to sort records in true alphabetical order is easily attainable by creating IF/THEN statements to outline your specific data sort.