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
Arjun y 7Arjun y 7 

I need to create a formula field for the below scenario

Hi All,

I need to create a formula field for the below scenario. I tried many ways to get the formula field.

Type Field contains two values. Those are
1.ASD8765
2.OPDQ76YTH

If Type field begins with 'A', the formula field should store the first 4 characters of the string as Formula field ='ASD8'
If Type field begins with 'O', the formual field should store the first 3 charaters of the string as Fomula field = 'OPD'

Can any one help me to solve this.

Thank You!!
Arjun
Best Answer chosen by Arjun y 7
Prem Anandh 1Prem Anandh 1
Hi Arjun, 

Please check below updated code. 

If the Type will start with 'A', It will take first 4 char of type and will populate on Formula field
If the Type will start with 'O', It will take first 3 char of type and will populate on Formula field
 
IF(
   LEFT(Code__c,1)  = 'A', LEFT(Code__c,4),
   IF(
       LEFT(Code__c,1) = 'O', LEFT(Code__c,3), ''
     )
  )

Please let me know if its works for you. 


Thanks,
Prem Anandh

All Answers

Prem Anandh 1Prem Anandh 1
Hi Arjun,

Please check with below code. 

Formula Field:
IF(
   ISPICKVAL(Type__c, 'ASD8765'), LEFT(TEXT(Type__c), 4), 
   IF(
      ISPICKVAL(Type__c, 'OPDQ76YTH'), LEFT(TEXT(Type__c), 3), ''
     )
  )

Screen-shot:
User-added image



Please let me know incase any queries

Thanks,
Prem Anandh
Arjun y 7Arjun y 7
Hi Prem,
Thank You!!
It is not a Picklist value.. It is a Text field.

Thanks for the response!!
Arjun y 7Arjun y 7
One more points is we need to search the above value with Begin keyword. If it is'O', we need to display only ASD8
Prem Anandh 1Prem Anandh 1
Hi Arjun, 

Please check below updated code. 

If the Type will start with 'A', It will take first 4 char of type and will populate on Formula field
If the Type will start with 'O', It will take first 3 char of type and will populate on Formula field
 
IF(
   LEFT(Code__c,1)  = 'A', LEFT(Code__c,4),
   IF(
       LEFT(Code__c,1) = 'O', LEFT(Code__c,3), ''
     )
  )

Please let me know if its works for you. 


Thanks,
Prem Anandh
This was selected as the best answer