[SalesForce] how can i count selected multi pick list values in report

I have a few multipicklist field in my contact and i would like to report on how many values selected for these fields per contact in report. Is that possible?

Best Answer

  1. Create a number field with 0 decimal places named Count_Of_Selections__c
  2. Create a text field named anything you want
  3. Create a WFR that copies the value of the MSPL to the text field in #2
  4. Create a WFR to populate that field with the count of items

LEN( Name)-LEN(SUBSTITUTE(Name,";",""))/LEN(";")+1

replacing NAME with your field from #2

  1. Use the field in #1 in your report

or you can follow the instructions here:

https://help.salesforce.com/HTViewSolution?id=000221353&language=en_US

But you have to updated the formula each time you add valued to the picklist and the compile size might be too big if you have a lot of values

Navigate to the fields area of the appropriate object.

  1. For standard objects, from Setup, click Customize, select the appropriate object, and click Fields.
  2. For custom objects, from Setup, click Create | Objects, and select one of the custom objects in the list.
  3. In Custom Fields & Relationships, click New.
  4. Choose the Formula as the type and click Next
  5. Enter a field label(Salesforce populates Field Name using the field label)
  6. Select the Formula Return Type as Number
  7. Choose the number of decimal places as 0
  8. Select the Advanced Formula
  9. To insert a function, double-click its name in the list, or select it and click Insert Selected Function

              IF(INCLUDES( Multi_Picklist_Field__c , "Value A"),1,0) +
              IF(INCLUDES( Multi_Picklist_Field__c , "Value B"),1,0) +
              IF(INCLUDES( Multi_Picklist_Field__c , "Value C"),1,0) +
              IF(INCLUDES(  Multi_Picklist_Field__c , "Value D"),1,0)
    
  10. To check your formula for errors, click Check Syntax and Save.

Basically there is no clean way to do it declaratively. A trigger could populate it much easier

trigger countItems on Account(before insert, before update){

     for(Account a : trigger.new){
          if(string.isblank(a.PICKLISTFIELD__c)) continue;
          a.MYCOUNTFIELD__c = a.PICKLISTFIELD__c.split(';').size();

     }

}