> For the complete documentation index, see [llms.txt](https://manual.bubble.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.bubble.io/help-guides/logic/dynamic-expressions.md). Agents can also search and read this documentation through its [MCP server](https://manual.bubble.io/~gitbook/mcp).

# Dynamic expressions

Dynamic expressions are live formulas that fetch and calculate data in your app. Learn how they're built from data sources, operators, and comparisons, and where to use them.

Dynamic expressions are like live formulas. Instead of typing in a fixed value, you tell Bubble where to find the value and what to do with it, and Bubble works out the result while your app runs. When the data changes, the result can change with it.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FVQRK50C6UyUX6z2AiOYN%2Fdynamic-expressions-count-example.png?alt=media&amp;token=bdc6400d-a674-4a90-ae3b-72e2b52f3a13" alt="A text element called Text User count on the canvas reading There are Search for Users:count users in your app, with the same expression highlighted in the Text property of the element property editor."><figcaption><p>This expression searches the database for users and counts them. The count updates on its own when users are added or removed.</p></figcaption></figure>

Expressions are one of Bubble's basic building blocks, and you'll use them almost everywhere: to show data in elements[^1], to set up conditions[^2] that decide whether something should happen, and to give the actions in a workflow[^3] the data they need.

Let's say you're building an app that tracks customer orders. You could use an expression to calculate the total cost of an order, based on the price and quantity of each item. Like a formula in a spreadsheet, the expression follows the data it depends on, so if a customer changes the quantity of an item, the total updates along with it.

{% embed url="<https://www.youtube.com/watch?v=mrh8OV79snk>" %}

***

## How dynamic expressions are structured

Expressions range from a single step to long chains, but they're all built from the same three parts:

<table><thead><tr><th width="176.859375">Part</th><th>What it does</th></tr></thead><tbody><tr><td><a href="#data-sources">Data source</a></td><td>Where the expression gets its data, such as the database, the current user, or an API</td></tr><tr><td><a href="#operators">Operator</a></td><td>Something you do with that data, such as counting, sorting, or calculating</td></tr><tr><td><a href="#comparisons">Comparison</a></td><td>Compares two compatible values, such as two numbers, two data types, or two texts, and returns yes or no</td></tr></tbody></table>

Every expression starts with a data source. You can then add one or more operators to transform, aggregate, or manipulate the data, and sometimes a comparison.

### Data sources

A *data source* is any place Bubble can get data from. That's not limited to the records in your database: any channel your app can draw information from counts. Here are a few examples:

| Data source                                             | What it returns                                                 |
| ------------------------------------------------------- | --------------------------------------------------------------- |
| [Do a search for](#user-content-fn-4)[^4]               | The things in your database that match the constraints you set  |
| [Current User](#user-content-fn-5)[^5]                  | The user who's using the app                                    |
| [Get an option](#user-content-fn-6)[^6]                 | One option, or all the options, from an option set              |
| [Get data from an external API](#user-content-fn-7)[^7] | The data returned by an API call                                |
| Current date/time                                       | The date and time on the user's device when the expression runs |
| [Current geographic position](#user-content-fn-8)[^8]   | The user's location, if they allow your app to access it        |

That's only a handful of them. Bubble has many more data sources, and the ones you see depend on where you're building the expression.

**Reference:** [Data sources](https://manual.bubble.io/core-resources/data/data-sources.md)

### Operators

{% hint style="info" %}
This section explains what operators are and how they work. For a list of every operator and what it does, see the core reference.

**Reference:** [Operators and comparisons](https://manual.bubble.io/core-resources/data/operations-and-comparisons.md)
{% endhint %}

Operators are functions you can apply to a data source, such as filtering, sorting, grouping, aggregating, and calculating. Which ones you can use depends on the type of data you're working with.

Let's go back to the example from the beginning of this article:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FVQRK50C6UyUX6z2AiOYN%2Fdynamic-expressions-count-example.png?alt=media&amp;token=bdc6400d-a674-4a90-ae3b-72e2b52f3a13" alt="A text element called Text User count on the canvas reading There are Search for Users:count users in your app, with the same expression highlighted in the Text property of the element property editor."><figcaption><p>The data source and the operator are separated by a colon.</p></figcaption></figure>

The expression has two steps, separated by a colon (:):

{% code overflow="wrap" %}

```
Search for Users:count
```

{% endcode %}

or

{% code overflow="wrap" %}

```
[Data source]:[operator]
```

{% endcode %}

<table><thead><tr><th width="181.87109375">Step</th><th>What it does</th></tr></thead><tbody><tr><td>Data source</td><td><code>Search for Users</code> uses the <em>Do a search for</em> data source to find users in the database.</td></tr><tr><td>Operator</td><td><code>:count</code> tells Bubble to count the results.</td></tr></tbody></table>

An expression returns the value of its last step. So this expression doesn't return a list of users. It returns a number that represents how many there are, such as 50.

#### Data-specific operators

Bubble adjusts the list of operators to the type of data the data source returns. In the example above, the data source returns a list of users, and since a list can be counted, the `:count` operator is available.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FrWMiToSwmVzzSsMDN7cS%2Favailable-operators-numbers.png?alt=media&amp;token=331d8215-c1c1-4203-8a70-ce8ca07260de" alt="The operator list open after Search for Users, showing options such as :count, contains, doesn&#x27;t contain, :first item, :last item, :random item, and :item #."><figcaption><p>Bubble lists the operators that fit the type of data. <em>Search for Users</em> returns a list of users, so you get list operators like <em>:count</em> and <em>:first item</em>.</p></figcaption></figure>

If you change the data source to one that returns another type of data, such as a date, the list of operators changes with it:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FFM3iuC4QczCwaGtvB4xL%2Fdate-operators.png?alt=media&amp;token=d953e188-d2b8-426b-8794-ac77fe9ad739" alt="The operator list open after Current date/time, showing options such as :formatted as 11/13/26, >, <, <- range ->, <- max ->, <- min ->, + seconds:, + minutes:, + hours:, and + days:."><figcaption><p>With <em>Current date/time</em> as the data source, Bubble shows date operators instead.</p></figcaption></figure>

Operators often change the type of data, too. In the first example, counting a list of users turns it into a number. With a datetime[^9], the result depends on the operator you pick:

<table><thead><tr><th width="321.05078125">Operator</th><th>What it returns</th></tr></thead><tbody><tr><td><code>:formatted as 11/13/26</code></td><td>A text, such as "11/13/26"</td></tr><tr><td><code>&#x3C;- range -></code></td><td>A <a data-footnote-ref href="#user-content-fn-10">date range</a> between two datetimes</td></tr><tr><td><code>+ seconds:</code>, <code>+ minutes:</code>, and the like</td><td>A datetime, moved forward by the amount you set</td></tr></tbody></table>

### Comparisons

Comparisons are the third part of an expression. They compare two values and return either yes or no. You can think of a comparison as a question that has a clear answer. Here's how a person might ask one:

```
Is 5 a bigger number than 3? Answer: yes
```

In an expression, the same question is written more like math:

```
5 > 3 = yes
```

The `>` symbol means *greater than*. In this example, 5 and 3 are both data sources, and `>` is the comparison. We're comparing the values of two data sources to get a yes or a no (or true and false, if you prefer).

Expressions are made for dynamic data, so let's compare two numbers that come from counting things. We've already counted the users. Let's say we also have a data type[^11] called *Post*, and we want to compare how many there are of each. The structure of the expression looks like this:

```
Data source:operator comparison data source:operator
```

```
Search for Users:count is Search for Posts:count
```

This time we use `is` instead of `>`. We're no longer asking whether one number is bigger, but whether the two are the same. Here's what that looks like in an expression:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2F4pRhj3msZ9dXdKmh9xjD%2Fcomparison-is.png?alt=media&amp;token=74f304d0-c960-4ee3-bafa-5899c8de50ea" alt="The Text property of a text element showing the expression Search for Users:count is Search for Posts:count."><figcaption><p>The <em>is</em> comparison checks whether the two counts are the same.</p></figcaption></figure>

If there are 50 users and 20 posts, the question we're asking is:

```
Is 50 the same as 20? Answer: no
```

#### Comparing other types of data

Comparisons can handle any type of data, as long as the two values can be compared. For example, we could ask:

```
Is "London" the same as "New York"? Answer: no
```

This time we're comparing two texts instead of numbers. The two aren't identical, so the answer is *no*. In an app, those names could come from the *Name* field[^12] on a data type called *City*:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FQfLIUCkMIoqm3NVskBbd%2Fcompare-text-dynamic-expression.png?alt=media&amp;token=9433702b-443d-4eaa-bd32-f427f21a410f" alt="A text element showing the expression Current User&#x27;s City&#x27;s Name is Search for Citys:first item&#x27;s Name."><figcaption><p>This comparison checks whether the two cities have the same name.</p></figcaption></figure>

This expression combines several data sources, operators, and a comparison to ask:

{% code overflow="wrap" %}

```
Is the name of the city saved on the current user the same as the name of the first city returned by this search? Answer: no
```

{% endcode %}

Here we compare the cities' *names*, which are texts. We could also ask Bubble whether the two cities are the same database record:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2F8dvm3qY4erP8DjWV9c60%2Fcompare-cities.png?alt=media&amp;token=2ca3bda1-fcf5-4d02-ac56-f7a7d89f766e" alt="A text element showing the expression Current User&#x27;s City is Search for Citys:first item."><figcaption><p>This comparison checks whether the two cities are the same record in the database.</p></figcaption></figure>

The question has now changed to:

{% code overflow="wrap" %}

```
Is the city saved in the current user's City field the same database record as the first city returned by this search? Answer: no
```

{% endcode %}

Both expressions return *no* in this example. But if two different cities share a name, such as Paris in Texas and Paris, the capital of France, the first expression returns *yes* and the second returns *no*: The cities have the same name, but they're not the same record.

It's worth thinking through what a comparison actually checks, so that it gives you the answer you expect.

***

## Adding dynamic expressions

Expressions can often be mixed with regular text, so the user sees one complete message. In the example from the beginning of this article, the expression that counts users sits inside a sentence:

```
There are [expression] users in your app.
```

Your users just see "There are 50 users in your app." The calculation happens behind the scenes.

To add an expression to a text field:

{% stepper %}
{% step %}

#### Place the cursor

Click in the field where you want the expression to go, such as the text field of a [**Text** element](#user-content-fn-13)[^13].
{% endstep %}

{% step %}

#### Insert dynamic data

Click the *Add dynamic* button that shows up next to the field, and pick a data source. Bubble adds the expression where the cursor is.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FTfMrUsrEYqAqhn2dy1Oy%2Fadd-expression.png?alt=media&amp;token=a8fecabe-8ed5-4833-972a-101036783f42" alt="The Add dynamic button, with the keyboard shortcut ⌘+/, to the left of a Text field that contains the placeholder text ...edit me..."><figcaption><p>To add a dynamic expression, click the blue <em>Add dynamic</em> button on the left side of the field. Until you hover over it, the button just says <em>Add</em>.</p></figcaption></figure>
{% endstep %}
{% endstepper %}

To delete an expression, click it and then click the trash icon in the popup that opens. You can also click it and press **Backspace**.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2Ff9xSWiqu1RHCP7KeGyYQ%2Fdelete-expression.png?alt=media&amp;token=86ae2270-8b09-4e4b-b32c-8fbc928f388e" alt="The popup for a Do a search for expression in a Text field, with the trash icon in its top bar highlighted."><figcaption><p>Click an expression to open its popup, and click the trash icon to delete it.</p></figcaption></figure>

***

## Where expressions are used

Expressions are such a central part of Bubble that you'll find them in a wide range of places. Let's look at the three most common ones.

### In elements

Expressions can give an element a value. We've already seen how an expression can show a count in a **Text** element. Here are two more examples.

#### Example: set tomorrow's date

In this example, we use an expression to show tomorrow's date in a **Text** element:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FjdM1aiI3MOcdakLQ0zLG%2Fdynamic-expression-tomorrows-date.png?alt=media&amp;token=e4cb3f74-5cfe-4152-a319-c6b194e210bb" alt="The Text property of a text element called Text Tomorrow, set to the expression Current date/time + days: 1."><figcaption><p>Combining the <code>Current date/time</code> data source and the <code>+ days:</code> operator, we can show tomorrow's date in a <strong>Text</strong> element.</p></figcaption></figure>

The `Current date/time` data source returns the date and time when the expression runs, and the `+ days:` operator moves it forward by one day. In plain words, we're telling Bubble:

{% code overflow="wrap" %}

```
Show the current date and time, plus one day
```

{% endcode %}

When the page loads, the user sees tomorrow's date.

#### Example: show users from two searches

A [repeating group](#user-content-fn-14)[^14] needs a data source, and that's set with an expression too. We could use a simple `Do a search for Users`, but to show how expressions can do more, let's add an operator:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FCdx3T2esh1CqxmC94Tt8%2Fintersect-with-operator-example.png?alt=media&amp;token=efbb40d1-233f-4cd3-9ca6-dcdc0709fe7d" alt="A repeating group with Type of content set to User and Data source set to Search for Users intersect with Search for Users."><figcaption><p>The <em>intersect with</em> operator returns only the users found by both searches.</p></figcaption></figure>

Here we use the [`intersect with`](#user-content-fn-15)[^15] operator to get a different list of users than either search would give us on its own. In plain words, we're telling Bubble:

{% code overflow="wrap" %}

```
Search for one set of users and a second set of users, and then return the users who are in both lists
```

{% endcode %}

If the two searches have different constraints, the repeating group shows only the users that are in both search results.

### In conditions

{% hint style="info" %}
This section gives a short overview of conditions. To learn more, including how to use conditions to keep your app secure, see the article on conditions.

**Article:** [Conditions](https://manual.bubble.io/help-guides/logic/conditions.md)
{% endhint %}

A condition is an expression that returns yes or no, and Bubble uses the answer to decide whether to *do* something or not. You can use conditions in three places:

<table><thead><tr><th width="329.0859375">Where</th><th>What the condition decides</th></tr></thead><tbody><tr><td>On an element</td><td>Whether to change the element's properties, such as hiding it or changing its style. See <a href="https://manual.bubble.io/help-guides/logic/conditions.md#element-conditions">Element conditions</a>.</td></tr><tr><td>On a workflow or an action</td><td>Whether the workflow or action should run when it's triggered. See <a href="https://manual.bubble.io/help-guides/logic/conditions.md#only-when-conditions-workflow-conditions">Only when conditions</a>.</td></tr><tr><td>In the <em>Do when condition is true</em> event</td><td>When to start a workflow. See <a href="https://manual.bubble.io/help-guides/logic/conditions.md#running-a-workflow-when-a-condition-is-true">Running a workflow when a condition is true</a>.</td></tr></tbody></table>

#### Example: hide an element for logged-out users

A *Sign out* button doesn't make much sense to a user who isn't logged in, so let's use a condition to hide it:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FflpqtiPCSqXlAzVgzNp0%2Fhide-button-when-logged-out.png?alt=media&amp;token=a06e7c4b-20e2-4dbb-9d8f-5402c7323aa8" alt="The Conditional tab of a button called Sign out, with a condition that turns off This element is visible when Current User is logged out."><figcaption><p>When the current user is logged out, this condition hides the <em>Sign out</em> button.</p></figcaption></figure>

<table><thead><tr><th width="91.6953125">Number</th><th>What's set up</th></tr></thead><tbody><tr><td>1</td><td>The expression uses the <code>Current User</code> data source and the <code>is logged out</code> operator to get a yes or no answer.</td></tr><tr><td>2</td><td>When the answer is <code>yes</code>, the <em>This element is visible</em> property is turned off, so the button is hidden.</td></tr></tbody></table>

In plain words, we're saying:

```
If the current user is logged out, hide this button
```

#### Example: stop a workflow from running

A condition can also decide whether a workflow runs when it's triggered. Let's say users can create a new blog post, and we don't want to create it if the user hasn't given it a title:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2F9JNtBnapQKFNgaxBvDJB%2Finput-is-empty-condition-example.png?alt=media&amp;token=11279057-1e36-41a2-836a-21c75a319ee6" alt="The Button Create blog post is clicked event, with the condition Input Blog post title&#x27;s value is not empty in the Only when section of the workflow property editor."><figcaption><p>The workflow only runs when the <em>Blog post title</em> input has a value.</p></figcaption></figure>

In this example, the data source is the input[^16] `Input Blog post title`, and we've added two operators:

<table><thead><tr><th width="198.2265625">Operator</th><th>What it does</th></tr></thead><tbody><tr><td><code>'s value</code></td><td>Returns the value from the input, which is the title the user gave the blog post</td></tr><tr><td><code>is not empty</code></td><td>Returns <code>yes</code> if the value has something in it, and <code>no</code> if it's empty</td></tr></tbody></table>

In plain words, we're saying:

```
Only run this workflow if the user has entered a title for the new blog post
```

### In workflows

{% hint style="info" %}
This section gives a short overview of how expressions work in workflows. To learn more about workflows, see the article below.

**Article:** [Workflows](https://manual.bubble.io/help-guides/logic/workflows.md)
{% endhint %}

Expressions also give the actions in a workflow the data they work with.

#### Example: save an average score

Let's say we run an app where users review blog posts. Along with the built-in *User* data type, we have a data type called *Review*, with a number field called *Score* where users give each blog post a score from 1 to 10.

As the user keeps reviewing blog posts, we want to save their *average* score on their profile. In this example, a workflow does that when the user clicks a button called *Calculate average review score*:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FpW6yi8HeXLK7XuRfru7N%2Fcalculate-average-example.png?alt=media&amp;token=2e2a71d9-a237-4813-9fe2-4ffcff2c2602" alt="The Button Calculate average review score is clicked workflow, with a Make changes to current user action that sets Average score to Search for Reviews:each item&#x27;s Score:average."><figcaption><p>The expression turns a list of reviews into one average score.</p></figcaption></figure>

<table><thead><tr><th width="269.2421875">Part</th><th>What it does</th></tr></thead><tbody><tr><td><a data-footnote-ref href="#user-content-fn-17">Make changes to a thing</a> action</td><td>Changes the current user, and sets a value in the field called <em>Average score</em>.</td></tr><tr><td><code>Search for Reviews</code></td><td>Finds the blog post reviews this user has written, using a constraint on the search, such as <code>Created By = Current User</code>.</td></tr><tr><td><code>:each item's Score</code></td><td>Turns the list of reviews into a list of numbers: the score from each review.</td></tr><tr><td><code>:average</code></td><td>Takes the list of numbers and calculates their average. The result is a number, which is what the <em>Average score</em> field expects.</td></tr></tbody></table>

In plain words, we're saying:

{% code overflow="wrap" %}

```
Find all the reviews this user has written, and save the average of their scores on the user
```

{% endcode %}

#### Example: create a date range from two dates

A date range stores the span between two datetimes, with a start and an end. It makes it simple to check things like whether a datetime falls within a specific range.

Let's say users pick the start and end dates of a vacation in two date/time pickers, and we want to turn them into a date range and store it in a custom state with the [**Set state of an element**](#user-content-fn-18)[^18] action. The values of the two pickers are the data sources, and the `<- range ->` operator combines them:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FVAVOUckz68iTdZdNAyPE%2Fdate-range-expression-example.png?alt=media&amp;token=a8910a74-0eb4-48eb-9a4e-5ab59f754848" alt="The Button Store date range is clicked workflow, with a Set states action where Element is set to index and the Date range custom state is set to Date/TimePicker Start date&#x27;s value <- range -> Date/TimePicker End date&#x27;s value."><figcaption><p>The <code>&#x3C;- range -></code> operator combines the values of the two date/time pickers into one date range.</p></figcaption></figure>

The workflow runs when the user clicks the *Store date range* button. In the action, *Element* is set to the page itself, *index*, since that's where we created the custom state. Under *Custom States*, the state called *Date range* is set to an expression that uses the `<- range ->` operator to combine the values of the *Start date* and *End date* pickers into one date range.

***

## Checking the value of an expression step

Every expression is made up of steps, and each step returns a value. Each of those values has a type, such as yes/no, number, text, or one of your data types.

In long expressions, it can be hard to keep track of what each step returns. To see the type of data, hover over the step:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FgjFhlPhPaa9gpQHz8zN4%2Fhover-expression.png?alt=media&amp;token=91c4a32d-3649-4de5-b3c3-82bca2e34519" alt="The mouse hovering over the last step of a date range expression in the Custom States section, with a tooltip that reads Evaluates to a date."><figcaption><p>Hover over a step in an expression to see the type of data it returns.</p></figcaption></figure>

This comes in handy when an expression doesn't behave the way you expect. A field only accepts an expression that returns the type of data it's expecting, so a step that returns the wrong type is a good place to start looking.

***

## Copy/pasting expressions

You can copy and paste a single expression, or everything in a field.

### Copy one expression

To copy a single expression, right-click it and select *Copy expression*.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FdIP2nR0LRyGNNozhrzM9%2Fcopy-paste-clear-expression-menu.png?alt=media&amp;token=45204c6b-7e10-4a02-b600-70ef19145a91" alt="Right-clicking an expression opens a menu with Copy expression, Paste expression, Clear expression, Convert to a global expression, and Reveal the element."><figcaption><p>Right-click an expression to copy it.</p></figcaption></figure>

To paste it, right-click a place that accepts an expression and select *Paste expression*. You may need to click *Add dynamic* first to create an empty expression.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FRFzM1vhVxcRxZPIrzRXb%2Fpaste-expression.png?alt=media&amp;token=a5224d31-a1ea-48b3-b8e7-cea0bbb0ab92" alt="Right-clicking an empty expression opens a menu with Copy expression, Paste expression, Clear expression, and Convert to a global expression."><figcaption><p>To paste, right-click a place that accepts an expression.</p></figcaption></figure>

### Copy all content in a field

To copy everything in a field, right-click inside the field, but outside the expression, and select *Copy*. This copies both the expressions and the regular text.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2Ffq5n2skmGYUapMJsHqeY%2Fcopy-whole-block.png?alt=media&amp;token=28361806-6f2b-4226-9b02-586577108f64" alt="Right-clicking inside a text field, outside the expression, opens a menu with Copy, Paste, Paste before, Paste after, and Clear all."><figcaption><p>Right-click outside the expression to copy everything in the field.</p></figcaption></figure>

To paste it, right-click inside a field that accepts it, but not on an expression.

***

## How expressions are processed

Bubble evaluates dynamic expressions from left to right. It reads each part of the expression in order, one at a time, starting with the leftmost part and moving to the right.

That's different from the mathematical order of operations that many programming languages and spreadsheets follow, where some operations, such as multiplication, come before others, such as addition.

<details>

<summary>What is the order of operations?</summary>

In math, the order of operations is a set of rules for which part of a calculation to do first: parentheses, then exponents, then multiplication and division, and finally addition and subtraction.

That's why 2 + 2 × 3 is 8 in math: You multiply 2 × 3 first, and then add 2. If you go from left to right instead, the same calculation gives you 12.

</details>

For example, Bubble reads `Current page width + 2 * 3` as `(Current page width + 2) * 3`. If you're used to other programming languages, this can lead to unexpected results, so it's worth keeping in mind. On the other hand, it means Bubble evaluates an expression in the same order you read it.

Bubble also doesn't do more work than it has to. When the parts of a yes/no expression are joined with the *and* operator and one of them returns *no*, Bubble already knows the answer and skips the rest. That means the order of the parts can make a difference to performance.

**Article section:** [Creating efficient expressions](https://manual.bubble.io/help-guides/logic/conditions.md#creating-efficient-expressions)

### Parentheses in dynamic expressions

You can have Bubble show the order of evaluation in your expressions by adding parentheses around their parts. To turn this on, go to the **Settings** tab, open the **General** section, and check *Show parentheses in dynamic expressions in editor* under *Advanced options*.

Parentheses also let you group part of an expression, so Bubble evaluates it first and treats the result as a value of its own. That makes some expressions possible that a single left-to-right chain doesn't allow, such as applying both `:trimmed` and `:lowercase` to the same value.

**Article section:** [Show parentheses in dynamic expressions in editor](https://manual.bubble.io/help-guides/getting-started/navigating-the-bubble-editor/tabs-and-sections/settings-tab/overview.md#show-parentheses-in-dynamic-expressions-in-editor)

***

## Display names in dynamic expressions

{% hint style="info" %}
Display names are only available in the redesigned property editor.

**Article:** [Navigating the redesigned property editor](https://manual.bubble.io/help-guides/getting-started/navigating-the-bubble-editor/tabs-and-sections/property-editor-beta/property-editor-migration-guide-for-existing-users.md)
{% endhint %}

You can give certain parts of an expression a name, so they're easier to recognize and read. For example, a `Do a search for` that searches for users where `admin = yes` can be named "All admin users," and a find and replace can be named "Remove commas." The name doesn't change how the expression works.

You can set display names on:

* Do a search for
* Arbitrary text
* Arbitrary date
* Find & replace

**Article section:** [Display name](https://manual.bubble.io/help-guides/data/the-database/finding-data.md#display-name)

***

## Reusing expressions with global expressions

If you use the same expression in several places, you can build it once as a global expression in the **Global** tab. It then shows up as a data source you can add to any dynamic expression in your app, through the `Use global expression` data source. When you change a global expression, the change applies everywhere it's used.

Global expressions can also take parameters, so each place that uses one can adjust it, for example by adding constraints to a search. Like display names, global expressions are only available in the redesigned property editor.

**Article:** [Global expressions](https://manual.bubble.io/help-guides/getting-started/navigating-the-bubble-editor/tabs-and-sections/styles-tab/global-expressions.md)

***

## Build dynamic expressions with Bubble AI

You can ask the [Bubble AI Agent](https://manual.bubble.io/help-guides/ai/bubble-ai-agent.md) to [create and edit dynamic expressions](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md#dynamic-expressions) for you. Select the element or workflow you're working on, and describe in plain language what the expression should do. The Agent looks through your app for the data sources and operators it needs, and depending on the approval mode you've picked, it can summarize the changes for you to approve before it makes them.

The Agent can also create global expressions, and it can explain or help you troubleshoot the expressions you've already built.

Here are a few prompts to try:

{% code overflow="wrap" %}

```
Change the data source of the Posts repeating group so it only shows posts written by the current user.
```

{% endcode %}

{% code overflow="wrap" %}

```
Make the Total text element show the sum of the prices of all the products in the current user's cart.
```

{% endcode %}

{% code overflow="wrap" %}

```
Create a global expression that formats a price with a currency symbol, and use it everywhere I display a price on the products page.
```

{% endcode %}

{% code overflow="wrap" %}

```
Explain what each step of the expression in this text element returns.
```

{% endcode %}

{% code overflow="wrap" %}

```
Why does the condition on this button never return yes?
```

{% endcode %}

**Article:** [Edit apps with AI](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md)

***

## FAQ: Dynamic expressions

<details>

<summary>What's the difference between a dynamic expression and a condition?</summary>

A condition is a dynamic expression that returns yes or no. Bubble uses the answer to decide whether something should happen, such as hiding an element or running a workflow. See [In conditions](#in-conditions).

**Article:** [Conditions](https://manual.bubble.io/help-guides/logic/conditions.md)

</details>

<details>

<summary>Does Bubble follow the mathematical order of operations?</summary>

No. Bubble evaluates expressions from left to right, so `Current page width + 2 * 3` is read as `(Current page width + 2) * 3`. You can turn on parentheses to see the order and to group parts of an expression. See [How expressions are processed](#how-expressions-are-processed).

</details>

<details>

<summary>Do expressions update automatically when the data changes?</summary>

Often, yes. When an element's data source uses `Do a search for`, it stays in sync with the database, so changes show up right away, even when another user made them. The exception is a search that was first fetched in a workflow.

Some data sources don't update on their own. For example, `Current date/time` returns the time when the expression runs, and you need to evaluate it again to get a newer time.

**Reference:** [Data sources](https://manual.bubble.io/core-resources/data/data-sources.md)

</details>

<details>

<summary>Why can't I pick an element or value in my expression?</summary>

A field only accepts a value of the type it expects. If an element or a step in your expression returns another type of data, you won't be able to select it, or the expression is flagged as an issue. Hover over each step to check what it returns. See [Checking the value of an expression step](#checking-the-value-of-an-expression-step).

</details>

<details>

<summary>What happens if an expression returns an empty value?</summary>

The expression returns an empty value, and whatever uses it gets nothing. If you need a fallback, add the `:defaulting to` operator, which returns a value you choose when the original expression is empty.

**Reference:** [Operators and comparisons](https://manual.bubble.io/core-resources/data/operations-and-comparisons.md)

</details>

<details>

<summary>Do dynamic expressions use workload?</summary>

Expressions that need Bubble's server, such as database searches, use workload. How much depends on how much data the search returns and how complex the expression is. For example, a search with a constraint that contains another search can multiply the number of searches.

**Article section:** [Dynamic expressions and WU](https://manual.bubble.io/help-guides/workload/optimizing-workload/optimization-checklist/searches.md#dynamic-expressions-and-wu)

</details>

<details>

<summary>Are dynamic expressions secure?</summary>

On a page, an expression can only return the data the current user is allowed to see, since [privacy rules](https://manual.bubble.io/help-guides/data/the-database/protecting-data-with-privacy-rules.md) filter the data on the server before it's sent to their device. When you use expressions in conditions to protect something, conditions the server can check, such as a field on the current user, are more secure than conditions based on something on the page, such as whether an element is visible.

**Article section:** [Using conditions for security](https://manual.bubble.io/help-guides/logic/conditions.md#using-conditions-for-security)

</details>

<details>

<summary>Do dynamic expressions work in native mobile apps?</summary>

Yes. If you're using [Bubble for native mobile apps](https://manual.bubble.io/help-guides/getting-started/building-for.../native-ios-and-android.md), you build expressions the same way. Some data sources are specific to the platform, such as `Current page width` on the web and `Current view's width` in a native mobile app.

</details>

<details>

<summary>How do I find out why an expression isn't working?</summary>

Start by hovering over each step to check what type of data it returns. To see what an expression returns while your app runs, preview the app and use the debugger. It shows the values of an element's expressions, and whether each of its conditions is true.

**Article section:** [Understanding expression evaluations](https://manual.bubble.io/help-guides/getting-started/navigating-the-bubble-editor/tools/using-the-debugger.md#understanding-expressions-evaluations)

</details>

<details>

<summary>Can I reuse the same expression in several places?</summary>

Yes. Build it once as a global expression, and use it anywhere in your app with the `Use global expression` data source. See [Reusing expressions with global expressions](#reusing-expressions-with-global-expressions).

</details>

[^1]: *Elements* are the objects that you place on the page as you design your app. There are many different types of elements, like texts, buttons, input fields, and calendars.\
    **Article series:** [Elements](https://manual.bubble.io/help-guides/design/elements.md)

[^2]: Conditions are expressions that return yes or no, and Bubble uses the answer to decide whether something should happen, such as showing an element or running a workflow.\
    **Article:** [Conditions](https://manual.bubble.io/help-guides/logic/conditions.md)

[^3]: A *workflow* is the combination of an event and one or more actions.\
    **Article:** [Workflows](https://manual.bubble.io/help-guides/logic/workflows.md)

[^4]: Bubble lets you set up flexible database searches and narrow down the results with dynamic constraints. Database searches are made with the *Do a search for* data source.\
    **Article:** [Finding data](https://manual.bubble.io/help-guides/data/the-database/finding-data.md)\
    **Reference:** [Do a search for](https://manual.bubble.io/core-resources/data/data-sources.md#do-a-search-for)

[^5]: The *Current User* data source returns the user who's currently using the app, so you can use the data saved on them.\
    **Article:** [User accounts](https://manual.bubble.io/help-guides/data/user-accounts.md)\
    **Reference:** [Current user](https://manual.bubble.io/core-resources/data/data-sources.md#current-user)

[^6]: Option sets let you set up static options in a database-like structure, without using the database. They're useful for things like days of the week, colors, or countries, which load quickly and rarely change.\
    **Article:** [Option sets](https://manual.bubble.io/help-guides/data/static-data/option-sets.md)

[^7]: An API call sends a request to an external app to get data back. For example, you could send a request to a weather service to get updated weather information. Outgoing API calls are made with the API Connector.\
    **Article:** [The API Connector](https://manual.bubble.io/help-guides/integrations/api/the-api-connector.md)

[^8]: The *Current geographic position* data source returns the user's location as a geographic address. The browser asks the user for permission first, and many browsers turn location sharing off by default, so it isn't a reliable way to get every user's location.\
    **Reference:** [Current geographic position](https://manual.bubble.io/core-resources/data/data-sources.md#current-geographic-position)

[^9]: Bubble always stores a date and a time together, which is why we call it a *datetime*. When you show only the date or only the time, you format the value as text, and the stored value stays the same.\
    **Article section:** [Quick facts about dates and times in Bubble](https://manual.bubble.io/help-guides/data/time-dates-and-time-zones.md#quick-facts-about-dates-and-times-in-bubble)

[^10]: A date range holds the span between two datetimes by storing a start and an end.\
    **Reference:** [Date range type](https://manual.bubble.io/core-resources/data/operations-and-comparisons.md#date-range-type)

[^11]: *Data types* are like containers for a specific kind of information, made up of fields. *User* is a built-in data type, and you can add your own, like *Product* or *Blog post*.\
    **Article:** [Data types and fields](https://manual.bubble.io/help-guides/data/the-database/data-types-and-fields.md)

[^12]: *Fields* are where a data type stores its information. You can create as many fields as you need, and each one has a type, such as text, number, or image.\
    **Article:** [Data types and fields](https://manual.bubble.io/help-guides/data/the-database/data-types-and-fields.md)

[^13]: The *Text* element shows static or dynamic text on the page.\
    **Reference:** [Text element](https://manual.bubble.io/core-resources/bubble-elements/element-properties/web-element-properties/visual-element-properties/text-element.md)

[^14]: A *repeating group* is a container element that shows a list of things, such as users, products, or blog posts. You design one cell, and Bubble repeats it for each entry in the list.\
    **Article:** [Repeating group element (web)](https://manual.bubble.io/help-guides/design/elements/web-app/containers/repeating-groups.md)\
    **Reference:** [Repeating group element](https://manual.bubble.io/core-resources/bubble-elements/element-properties/web-element-properties/container-properties/repeating-group-element.md)

[^15]: *Intersect with* is an operator that takes two lists of things and returns the entries that are in both lists.\
    **Reference:** [Intersect with](https://manual.bubble.io/pages/-MTpydODwo34mk5NucJy#...-intersect-with-...)

[^16]: *Input forms* are elements that accept information from the user, such as a text field, a checkbox, a date picker, or a dropdown.\
    **Article:** [Input forms](https://manual.bubble.io/help-guides/design/elements/web-app/input-forms.md)

[^17]: *Make changes to a thing* saves changes to a specific thing in the database, such as a user's name or a product's image.\
    **Article:** [Creating, saving and deleting data](https://manual.bubble.io/help-guides/data/the-database/creating-saving-and-deleting-data.md)\
    **Reference:** [Make changes to a thing](https://manual.bubble.io/core-resources/bubble-workflows/bubble-actions/database-actions.md#make-changes-to-thing)

[^18]: *Set state of an element* sets the value of a custom state on an element. Custom states are like variables that store information temporarily, until they're updated or the page is reloaded.\
    **Article:** [Custom states](https://manual.bubble.io/help-guides/data/temporary-data/custom-states.md)\
    **Reference:** [Set state of an element](https://manual.bubble.io/core-resources/bubble-workflows/bubble-actions/element-actions.md#set-state-of-an-element)
