What is a custom formula for?
As Milliman Mind converts your excel file in a C# object-oriented model, you will need to rewrite your VBA functions which are not compatible with Mind.
If your VBA functions are designed to add a stochastic dimension to your model, Mind will handle this dimension natively.
But if you are doing any other work in Visual Basic, you will need to rewrite them in C# to be used in Mind.
Your custom C# formulas will be available in your model in replacement of your VBA functions, and once a formula is added to a company it will be available for any project created by any user of this company.
Create new formula
Connect to the administration interface, then click on Tools, then C# formulas.
To create a new formula, click on the Create new formula button in the top-right corner.

The formula editor will open. First name your formula without any spaces or special characters except - and _. Please note names are case-sensitive.
Then add one or many parameters, use the parameters text area.
Enter the code of your C# function in the editor using the parameters you defined earlier, and using C# syntax and rules.

To save your formula, click on Create new Formula.
Draft status
If your formula does not compile well when you save it, we will add a Draft tag and it will not be available in projects.
You can also access the history of versions of your formula with the dropdown on the top of the formula name.
Formulas in your project
A new Formulas button in the action bar appears if you are using formulas.
Click on it to display the used formulas for this project.
It will display the code of all formulas used in the project. If some formulas have been updated since the project was uploaded, you will be able to update them to the latest version by clicking on Update formulas.

Example
Below is a short example of a C# custom formula.
Admin display:

Raw code:
public static object Example(double value1, double value2, double value3, string condition, VirtualGrid grid)
{
int i;
// You can also use all Excel and Mind functions with adding Am. prefix. For example Am.OFFSET(...) or Am.MM_SIMULATE(...)
// Math namespace has a lot of useful basic mathematical functions (Min, Max, Round, Truncate, Pow, Sqrt, etc.)
double max = Math.Max(Math.Min(value1, value2), value3);
double result1 = 0.0;
double result2 = 0.0;
double conditionValue = 20.0;
// or condition - ||, and condition - &&
if (max <= conditionValue && (condition != "Calculate" || condition == "Calculate2"))
{
return conditionValue;
}
else
{
// Use method NbRows and NbCols to get number of rows and columns in the range
for (i = 0; i < grid.NbRows; i++)
{
for (int j = 0; j < grid.NbCols; j++)
{
// To access value in the cell of a range we use method Cell with number of row and column as a parameters
// Indices starts from 0
// Need to cast grids cell to double in case we expect number otherwise we should cast it to string: (string)grid.Cell(i,j)
// += operator is equal to result = result + ... ( the same way -=, *=, /=)
// Use % for determining the remainder of division
result1 += (double)grid.Cell(i, j) * Math.Truncate(value1) + Math.Round(value2, 2);
// Also can use simpiler method to access VirtualGrid values
result2 += (double)grid[i, j];
}
}
}
// If you have Range of just doubles, you can use specific functions to retrieve all values to double[,] array directly
// And after work with result array
double[,] doubleGrid = grid.DoubleGrid();
for (i = 0; i < doubleGrid.GetLength(0); i++)
{
for (int k = 0; k < doubleGrid.GetLength(1); k++)
{
result2 -= doubleGrid[i, k];
}
}
return result1;
}