Optimize the formula field with multiple If statements #inSalesforce

Optimize the formula field with multiple If statements:


Suppose the formula is:

IF(sampleField__c < 01000, "00000-01000", 
IF(sampleField__c < 02000, "01000-02000", 
IF(sampleField__c < 03000, "02000-03000", 
IF(sampleField__c < 04000, "03000-04000", 
IF(sampleField__c < 05000, "04000-05000", 
IF(sampleField__c < 06000, "05000-06000", 
IF(sampleField__c < 07000, "06000-07000", 
IF(sampleField__c < 08000, "07000-08000", 
IF(sampleField__c < 09000, "08000-09000", 
IF(sampleField__c < 10000, "09000-10000", 
IF(sampleField__c < 11000, "10000-11000", 
IF(sampleField__c < 12000, "11000-12000", 
IF(sampleField__c < 13000, "12000-13000", 
IF(sampleField__c < 14000, "13000-14000", 
IF(sampleField__c < 15000, "14000-15000", 
IF(sampleField__c < 16000, "15000-16000", 
IF(sampleField__c < 17000, "16000-17000", 
IF(sampleField__c < 18000, "17000-18000", 
IF(sampleField__c < 19000, "18000-19000",
null
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)



Solution:


Try like:

LPAD(TEXT(floor(sampleField__c / 1000)), 2, "0") + "000" +
"-" +
LPAD(TEXT(floor(sampleField__c / 1000) + 1), 2, "0") + "000" 

Comments