> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cfo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Common formula patterns

These patterns use supported formula syntax. Replace the example property and dimension names with names from your model.

## Gross profit

```text theme={null}
Revenue - `Cost of Goods Sold`
```

## Gross margin

```text theme={null}
if(Revenue <> 0, (Revenue - `Cost of Goods Sold`) / Revenue, 0)
```

## Variance

```text theme={null}
Actual - Plan
```

## Variance percentage

```text theme={null}
if(Plan <> 0, (Actual - Plan) / Plan, 0)
```

## Previous-period change

```text theme={null}
Revenue - Revenue[[-1]]
```

At monthly grain, this compares the current month with the previous month.

## Total across a dimension

```text theme={null}
sum(Revenue[Department: ANY])
```

## Share of total

```text theme={null}
if(sum(Revenue[Department: ANY]) <> 0, Revenue / sum(Revenue[Department: ANY]), 0)
```

Because the plain `Revenue` follows the current segment, this produces each department's share when calculated by Department.

## Average across selected segments

```text theme={null}
average(Revenue[Region: {"East", "West"}])
```

## Forecast driver formula

```text theme={null}
Headcount * `Average Salary`
```

Assign the formula to Forecast when Actuals should continue to use imported values.

## Conditional assumption

```text theme={null}
if(Revenue > 100000, Revenue * 0.05, Revenue * 0.03)
```

## Calendar-year end

```text theme={null}
date(year(Date.Month), 12, 31)
```

Before saving a pattern, confirm its target property, scope, Date grain, and scenario.
