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
PrasanthiPrasanthi 

Change in formula field

Hi

 

I have 4 fields – amount, cost, profit and profit %.

 

Profit = amount – cost

Profit % = profit/100 – upto 1 decimal place.

 

 

Is it possible if we enter profit and get profit % and vice versa… i.e  we enter the percentage and get profit.

 

Example – we enter 11.4% and the profit field is calculated to a value -1120.

And if other way around, we enter 1120 in profit, we get 11.4% in profit % field.

phiberoptikphiberoptik

A field can only have one type and does not have the functionality to flip flop types. A formula field is always  a formula field and is always Read-Only so you can never write to it.

 

You could get really clever and make both Profit and Profit % input fields such as Profit is Currency and Profit % is a Percent type field. Then create a formula field that looks at both the Profit and Profit % and calculates a value depending on which one is entered. Example formula:

 

IF(NOT(ISBLANK(Profit__c)), "Profit %: " & Profit__c/100 & "%",

     IF(NOT(ISBLANK(Profit_%__c)), "Profit: $" & Profit_%__c * 100,

null))

 

You would then want to have a validation rule that did not allow both Profit and Profit % to have values or the formula would break.

 

With the above formula, if $5,000 was entered into Profit field, the formula field would display Profit %: 500%.

If 500 was entered into the Profit % field, the formula field would display Profit: $5000.