function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chad RitchieChad Ritchie 

Removing Last Word of String

Hey guys,

How could I add some logic into this formula to remove the last "and" of every string. It's a multi-select-picklist. I know how to do this in a new formula using left(len()-4) and referring to the field, but how could this be done all in this same formula field? (trying to save some syntax size) Here's the formula:

IF(INCLUDES(Strategy__c, "A"), "A, and", NULL)+ IF(INCLUDES(Strategy__c, "B"), "B, and ", NULL)+ IF(INCLUDES(Strategy__c, "C"), "C, and", NULL) + IF(INCLUDES(Strategy__c, "D"), "D, and ", NULL) + IF(INCLUDES(Strategy__c, "E"), "E, and ", NULL) + IF(INCLUDES(Strategy__c, "F"), "F, and ", NULL) + IF(INCLUDES(Strategy__c, "G"), "G, and", NULL) + IF(INCLUDES(Strategy__c, "H"), "H, and" NULL) + IF(INCLUDES(Strategy__c, "I"), "I, and ", NULL) + IF(INCLUDES(Strategy__c, "J"), "J, and ", NULL) + IF(INCLUDES(Strategy__c, "K"), "K, and ", NULL) + IF(INCLUDES(Strategy__c, "L"), "L, and ", NULL) + IF(INCLUDES(Strategy__c, "M"), "M, and ", NULL) + IF(INCLUDES(Strategy__c, "N"), "N, and ", NULL) + IF(INCLUDES(Strategy__c, "O"), "O, and ", NULL) + IF(INCLUDES(Strategy__c, "P"), "P, and ", NULL)

Thanks!!
Andrew GAndrew G
Reading the formula, do I expect the following:
Multi pick list field has : Apples, Bananas, Carrots as options
Your formula field displays Apples, and     or maybe Bananas, and Carrots, and   dependent on options selected? 

And you want instead to see Apples   or Bananas and Carrots   ?

Why not wrap the entire formula in the left(len( long formula here  )-4)  ?   Not tested but i think it would work. 


Regards
Andrew G

 
Andrew GAndrew G
My bad, just tested and you would have to repeat the formula:
LEFT( 
IF(INCLUDES(Fruit__c , "Apples"), "Apples, and ", NULL) +
IF(INCLUDES(Fruit__c , "Bananas"), "Bananas, and ", NULL) +
IF(INCLUDES(Fruit__c , "Carrots"), "Carrots, and ", NULL),
                LEN(
IF(INCLUDES(Fruit__c , "Apples"), "Apples, and ", NULL) +
IF(INCLUDES(Fruit__c , "Bananas"), "Bananas, and ", NULL) +
IF(INCLUDES(Fruit__c , "Carrots"), "Carrots, and ", NULL)
                ) - 6 )

in which case, perhaps have field_1 with long formula
and then 
LEFT( field_1, LEN( field_1 ) - 6 )
Jolly_BirdiJolly_Birdi
Hello @Chad

The thing which you want that can be done with trigger easily.

Thanks,
Jolly Birdi