# Advanced Functions

## Overview

Microsoft has added two powerful features in recent years which effectively allow users to create custom functions.

There are many benefits to using these functions, including:

* Improved readability of formulas
* Minimising the number of references to Calculation inputs
* Making complex functions reusable

To understand how LET and LAMBDA functions work, we recommend reading the Microsoft documentation. Links are included in the relevant sections below.

{% hint style="warning" %}
LET and LAMBDA functions are available in Office 365 versions of Excel. If you are using older versions of Excel, you can still use these functions within Models, but they will not produce working Excel spreadsheets.
{% endhint %}

## LET functions

{% hint style="info" %}
If you are new to LET functions, first read the [**Microsoft documentation here**](https://support.microsoft.com/en-us/office/let-function-34842dd8-b92b-4d3f-b325-b8b8f9908999)
{% endhint %}

To create a LET function, you can type the function into the [**Formula Entry Bar**](/calculations/the-calculation-page/the-formula-entry-bar.md), as you would for any other function, with two key differences: **Arguments** (called "variables" in the Microsoft documentation) and **References** to those arguments must be entered via the AutoComplete dropdown. This is demonstrated in the example below.

<figure><img src="/files/TzUMWT9Yvl2qwoZeHN1y" alt=""><figcaption><p>A LET function to find a root of a quadratic equation</p></figcaption></figure>

Let's say we want to create a LET function to find one of the roots of a quadratic equation, as shown above. This is useful as the arguments `a` and `b` are both used twice in the formula, so using a LET function means we only have to enter the input values for those arguments (which could be references to Variables) once.

When we enter each of the arguments (`a`, `b`, and `c`), we type in the name of the argument and then select the Argument Calculation Part with the plus in braces symbol<img src="/files/7ufyKQlNy6FFHGKgVqwR" alt="" data-size="line">from the AutoComplete dropdown, as shown below.

<figure><img src="/files/a8hf8QcnpGjSaEQjTxjY" alt=""><figcaption><p>Creating a LET argument</p></figcaption></figure>

To reference these arguments, we type in the name of the argument, and select the Argument Reference Calculation Part with the comma in braces symbol <img src="/files/jOycrrdsmfJCxBAle2OV" alt="" data-size="line">, as shown below.

<figure><img src="/files/j96mgU96RRFCeaSg9BMj" alt=""><figcaption><p>Referencing a LET argument</p></figcaption></figure>

## LAMBDA functions

{% hint style="info" %}
If you are new to LAMBDA functions, first read the [**Microsoft documentation here**](https://support.microsoft.com/en-us/office/lambda-function-bd212d27-1cd1-4321-a34a-ccbf254b8b67)
{% endhint %}

### Creating a Lambda

To create a LAMBDA function, go to the Lambda applet, which is accessible from the [**Navigation Bar**](/using-taglo-software/the-taglo-interface/navigating-in-models.md), or create one [**on the fly from the Formula Entry autocomplete menu**](/calculations/the-calculation-page/the-formula-entry-bar.md#full-list-of-autocomplete-option-types).

Lambdas are stored separately from Models so can be used in any Model that has access to the Lambda's [**Namespace**](/using-taglo-software/namespaces.md).

When you create a new Lambda you will need to perform the following steps, as per the screenshots below:

* Select a Namespace
* Choose a Name <mark style="color:green;">**(1)**</mark>. The name must obey Excel naming rules for [**Named Ranges**](https://support.microsoft.com/en-us/office/define-and-use-names-in-formulas-4d0f13ac-53b7-422e-afd2-abd7ff379c64), and not include spaces or certain special characters. The full rules are complex so we will not list them here, but the Lambda dialog will not let you proceed if the name does not meet the rules.
* Create the Arguments for the function <mark style="color:green;">**(2)**</mark>
* Enter the formula <mark style="color:green;">**(3)**</mark>

<figure><img src="/files/BlOnVVre82Pc6NLRQWA7" alt="" width="483"><figcaption><p>Creating a Lambda</p></figcaption></figure>

The Calculation entry step for a Lambda uses the same [**Formula Entry Bar**](/calculations/the-calculation-page/the-formula-entry-bar.md) as Variables, but with reduced capabilities (e.g. as Lambdas exist outside Models, you cannot reference Variables or Periods in a Lambda formula).

{% hint style="info" %}
Lambdas can reference other Lambdas - use this to greatly simplify complex calculations
{% endhint %}

### Using a Lambda function

Once you have created a Lambda function, it can be used in Models just like any other Function, as long as the Lambda's Namespace is available in your Model.

For instance, to use the `QuadraticRoot` Lambda from the above example, we would simply type the name of the Lambda into the Formula Entry Bar, select the function from the dropdown, and enter arguments as desired, as shown below.

<figure><img src="/files/2IOzxTwR5tAv9lVbi54F" alt=""><figcaption><p>Using a Lambda function in a Calculation</p></figcaption></figure>


---

# Agent Instructions: 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:

```
GET https://help.taglo.io/calculations/calculation-parts/functions/advanced-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
