> For the complete documentation index, see [llms.txt](https://docs.fabricplan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fabricplan.com/planning-sheets/how-tos/optimize-overview/use-optimize-on-derived-measures-and-allocation-rules.md).

# Use Optimize on derived measures and allocation rules

Optimization can also work on a formula measure that is itself derived from another formula measure. Optimize works backward through the measure dependencies and adjusts the same underlying input variables. The optimizer evaluates the complete formula chain and adjusts the underlying independent variables to achieve the specified target.

Use rules to control how Optimize adjusts underlying values while achieving a specified target. Apply locking rules to protect specific values, distribution rules to control how values are allocated, and min-max rules to enforce allowable value ranges during optimization. This provides greater control over the optimization process while preserving defined business constraints.

In this article, you learn to apply optimization to

* Derived measures that reference a formula
* Measures bound by allocation rules

### Prerequisites

Before you begin, review the [Prerequisites section for Optimize](/planning-sheets/how-tos/optimize-overview.md#prerequisites) to understand the initial setup requirements.

### Run Optimize on derived measures

The steps to configure Optimize and define constraints are the same as for [target-based ](/planning-sheets/how-tos/optimize-overview/optimize-input-values-to-meet-a-target.md)and [direction-based](/planning-sheets/how-tos/optimize-overview/maximize-or-minimize-a-target-value.md) optimization. The difference is that the calculated measure used for optimization can be derived from another calculated measure.

Example: Instead of optimizing *Profit Forecast* to reach a specific value, maximize *Margin %*. The optimizer can adjust *Revenue Forecast, Advertising Forecast, Transport Forecast,* and *Purchase Forecast* to find a combination that achieves the margin target.

1. Create the first-level formula that uses data input or forecast measures as underlying independent variables.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FlAQwWalZHiJPU931TIS7%2Fimage.png?alt=media&amp;token=bfe79bfb-351d-461a-a441-75237741d4e5" alt=""><figcaption></figcaption></figure>

2. Create a dependent formula. In this example, you define Margin % as `Profit Forecast / Revenue Forecast`. Margin % therefore depends on the Profit Forecast formula, which in turn depends on the four underlying forecast measures.

{% hint style="info" %}
Ensure the row and column aggregation types are set to **Formula**.
{% endhint %}

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2Fz0O5xJ4qQIHPenHOReIQ%2Fimage.png?alt=media&amp;token=616a2fe6-4642-40e4-9ba5-ae30c9670d63" alt=""><figcaption></figcaption></figure>

3. Select a target cell in the dependent formula. Then, in the **Planning** ribbon, select **Optimize**.
4. Select the optimize objective. Notice that the **Variables to Update** are the forecast measures used in the first-level formula created in step 1.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvlbFiqkAQlIB8e6q05Ug%2Fimage.png?alt=media&amp;token=c3559a1a-f50d-4f99-b983-2771f6ea0456" alt=""><figcaption></figcaption></figure>

5. Define thresholds for optimizing the independent measures. For more information, see [Configure optimization thresholds](/planning-sheets/how-tos/optimize-overview.md#configure-optimization-thresholds).

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FFCGHB9OyrKEFKqPKBEZy%2Fimage.png?alt=media&amp;token=62e7cdd8-e5c0-4d78-b9f8-8ab0b8d33e70" alt=""><figcaption></figcaption></figure>

6. Review the optimized values for the underlying independent variables and target measure. Then, select **Apply** to update the measures in the planning sheet with the optimized values.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F5NwjYpD0GB7kH5HSJYiy%2Fimage.png?alt=media&amp;token=bbf4918c-351c-45b8-bf69-6df12ff0832c" alt=""><figcaption></figcaption></figure>

7. Notice how Optimize updates the underlying *Revenue Forecast, Purchase Forecast, Advertising Forecast,* and *Transport Forecast* measures to achieve the target *Margin %*.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FpcwhQndRT8t1iBsSK4sX%2Fimage.png?alt=media&amp;token=ec9bf21c-487e-41de-92f4-7f6e4c7b31de" alt=""><figcaption></figcaption></figure>

8. To convert the *Margin %* to a percentage value, select the measure and select the **%** icon from the **Planning** ribbon. Ensure **Row Aggregation** and **Column Aggregation** are set to **Formula** to optimize the measure further.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2Fcx4gTuUCBmhaWA9FOg4s%2Fimage.png?alt=media&amp;token=0a93e6b0-cf23-4176-95f0-bae21737d81d" alt=""><figcaption></figcaption></figure>

### Apply rule-based optimization

Define rules to control how Optimize modifies the underlying measures during optimization. Use different rule types to restrict edits, control value distribution, or enforce allowable value ranges.

* Locking rules restrict edits to specific rows, columns, or periods during optimization.
* Distribution rules control how values are allocated across measures and dimensions.
* Min-max rules enforce minimum and maximum values for measures during optimization.

For example, optimize *Margin %* while preventing changes to the *North America Purchase Forecast*. This allows Optimize to adjust other underlying variables while keeping specified values unchanged.

1. To create a rule, in the **Model** ribbon, select **Rule**, then select a rule type. In this example, you select **Locking rule**.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2Fw73n8vUVKZzQ8qlzIB4C%2Fimage.png?alt=media&amp;token=c03b56a6-fb1e-4a16-a05d-7b6ab3e529ce" alt=""><figcaption></figcaption></figure>

2. To lock edits to *Purchase Forecast*, set **Apply to Measures** to **Selected Measures**, then select **Purchase Forecast** from **Choose Measures**. To lock edits to the *North America* row category, set **Row Selection** to **Custom** and select **North America** from **Custom Rows**.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FqsnYEFW8oeVc5PWxA9P8%2Fimage.png?alt=media&amp;token=4ab6bdd8-055d-442f-b019-ce0719820759" alt=""><figcaption></figcaption></figure>

3. Follow the same steps outlined in the [Run Optimize on derived measures](#run-optimize-on-derived-measures) section to configure Optimize. Note that the *Purchase Forecast* for *North America* is locked for editing.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FFr8xFTsX23EyJw3xomRB%2Fimage.png?alt=media&amp;token=2cb317f7-d29e-4d4c-b51e-c8e15ffb4f29" alt=""><figcaption></figcaption></figure>

4. The target value is achieved by optimizing the other values while preserving the values protected by the locking rule.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FzRz3dQkIRu7WgeZGZVYy%2Fimage.png?alt=media&amp;token=19bfcd7c-50b0-4dbf-8915-c24d50aeef46" alt=""><figcaption></figcaption></figure>

5. To convert the *Margin %* to a percentage value, select the measure and select the **%** icon from the **Planning** ribbon. Ensure **Row Aggregation** and **Column Aggregation** are set to **Formula** to optimize the measure further.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FMh7mOGZLJCPVoN6sx7JI%2Fimage.png?alt=media&amp;token=4b6049ac-56c0-4729-bcea-438e5f609ec4" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fabricplan.com/planning-sheets/how-tos/optimize-overview/use-optimize-on-derived-measures-and-allocation-rules.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
