Answered
I have 3 columns:
Retail Price £1.83 Gross Margin £0.93 Gross Percentage 50.70%
I need a calculation that will allow me to calculate the Gross Percentage (50.70%)
Can any one help, please.
Regards
Oldboy
// document level funciton
function Percent(nItem, nBse) {
/*
compute the percentage that nItem's value of the nBase's value
*/;
// variable for percentage
var nPercentage = 0;
// compute percentage if there is a base value;
if(nBase.toString() != "" | nBase != 0) {
nPercentage = nItem / nBase;
}
return nPercentage;
} // end Percent ;
// end document level function;
You can now use a custom calculation script like:
// custom calculation script;
// variables for field names;
var sGrossRevenue = "Retail Price"; // retail price
var sGrossMargin = "Gross Margin"; // gross margin amount
// get the base field value;
var nGrossRevenue = this.getField(sGrossRevenue).value;
// get item fields value;
var nGrossMargin = this.getField(sGrossMargin).value;
// set the default result format;
AFNumber_Format(0, 0, 0, 0, "",false);
if(nGrossRevenue == 0) {
event.value = "";
} else {
// compute percentage;
event.value = Percent(nGrossMargin, nGrossRevenue);
// format result as a percentage;
AFPercent_Format(2, 0);
}
The above script will display an empty string if Gross Revennue is zero or balnk.
George Kaiser