---
title: Import and query data using the Databricks Excel Add-in
description: Use the Databricks Excel Add-in to import and analyze data in Microsoft Excel with tables, SQL queries, pivot tables, custom functions, and templates.
canonical_url: https://docs.databricks.com/aws/en/integrations/excel/query-data
---

# Import and query data using the Databricks Excel Add-in

The Databricks Excel Add-in connects your Databricks workspace to Microsoft Excel, bringing governed Lakehouse data directly into your spreadsheets.

This page describes how to use the Databricks Excel Add-in to import and analyze data from Databricks in Excel. You can browse and import Databricks tables through an intuitive interface where no SQL knowledge is required. While the add-in offers the flexibility to execute custom SQL queries, it is optional.

## <a id="prereqs" />Prerequisites

* Before you use the Excel Add-in, verify that you have it [set up](https://docs.databricks.com/aws/en/integrations/excel/connect.md).
* You have [Databricks SQL access](https://docs.databricks.com/aws/en/security/auth/entitlements.md) and at least CAN USE permission on a [SQL warehouse](https://docs.databricks.com/aws/en/compute/sql-warehouse/index.md).

## Select a SQL warehouse

Choose which SQL warehouse to use:

1. In the upper-right of the Databricks Add-in pane in Excel, click the drop-down menu.
2. Select which SQL warehouse you want to use.

## <a id="import-data" /> Import data from Databricks

Import data from Databricks in Excel by selecting a table, writing a SQL query, importing a pivot table, or using a template.

> [!NOTE]
>
> You can import Unity Catalog metric views using pivot tables, SQL queries, and custom functions.

### <a id="pivot" />Create pivot tables

To create a pivot table from Unity Catalog tables and views in Excel:

1. In the Databricks Excel Add-in pane, under the **New import** tab, select **Select data** as the **Import method**.
2. Under **Catalog**, select the table you want to create a pivot table from and click **Select**.
3. Select the **Pivot Data** checkbox.
4. (Optional) Select **Live query** to run the query and automatically update a new worksheet as you build the pivot table. For more information, see [Live query](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#live-query).
5. Configure **Row**, **Column**, and **Value** by dragging each field to the correct area.
6. (Optional) Add a **Filter**. For more information about filters, see [Filter imported data](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#filters).
7. (Optional) Set a row limit for your import.
8. Import your results. Choose one of the following:

   * Click **Save and import** to save the query for reuse in the Excel workbook and import the results.
   * Click the down arrow, then click **Import results** to import the results without saving the query. Use this option when you want to continue editing an import.

   > [!NOTE]
   >
   > Pivot tables can only be imported to a new sheet.

When working with Unity Catalog metrics in pivot tables, you might see `Sum(measure)` displayed in the results. This is expected behavior and no additional aggregation occurs. Excel requires that values have an aggregation function, but because the data contains unique values, no aggregation occurs.

#### Live query

Live query runs your pivot query and updates the worksheet automatically as you edit the pivot, so you see results as you update fields instead of after clicking **Import**. Live query re-runs the query after you change at least one row or column and one value. To return to the standard flow, turn off the feature.

When Live query is enabled, the pivot table is always created and updated in a new sheet. Additionally, the pivot builder shows a **Save import** button in place of **Import**.

If Excel closes while you are editing a live pivot, the **Imports** tab shows a recovery option so you can restore the last saved configuration for that import.

### <a id="select-table" />Select tables

Data is imported as an Excel table object. You can move the table or rename the sheet, and the Excel Add-in refreshes data in the new location.

To import data from a Databricks table, do the following:

1. In the Databricks Excel Add-in pane, under the **New import** tab, select **Select data** as the **Import method**.
2. Choose a table to import from the Catalog explorer. You can filter the catalog by owner, certification status, and other properties using ![Sliders icon.](https://docs.databricks.com/aws/en/images/product-icons/SlidersIcon.svg) filter.
3. Click **Select**.
4. Under **Columns**, click the down arrow and deselect the columns you don't want to import, or leave all columns selected to import the entire table.
5. (Optional) Add a **Filter**. For more information about filters, see [Filter imported data](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#filters).
6. (Optional) Under **Sorting**, add one or more columns to sort by. For more information about sorting, see [Sort imported data](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#sort).
7. (Optional) To see a sample of the import, click **Preview**.
8. (Optional) Set a row limit to restrict the number of rows imported.
9. (Optional) To identify your imported data, enter an **Import name**.
10. Under **Output Destination**, choose to import the data to a new sheet or the current sheet. If you import to the current sheet, data starts at the cell reference you enter (by default A1).
11. Import your results. Choose one of the following:
    * Click **Save and import** to save the query for reuse in the Excel workbook and import the results.
    * Click the down arrow, then click **Import results** to import the results without saving the query. Use this option when you want to continue editing an import.

### <a id="write-query" />Write SQL queries

The **Write SQL** import method supports SQL functions and stored procedures.

To run custom SQL queries against your Databricks workspace, do the following:

1. In the Databricks Excel Add-in pane, under the **New import** tab, select **Write SQL** as the **Import method**.

2. Enter a name for your query to identify it later.

3. Write a new query or use an existing query from your Databricks workspace.
   * Write your SQL query in the editor. You can query any table in Unity Catalog that you have permissions to access.
     * Click ![Data icon.](https://docs.databricks.com/aws/en/images/product-icons/DataIcon.svg) Catalog explorer to view your schemas and tables.
   * To use a query from your Databricks workspace or an existing query in Excel, click ![Folder icon.](https://docs.databricks.com/aws/en/images/product-icons/FolderIcon.svg) the folder. If you use an existing query from your Databricks workspace, edits made in Excel are not reflected on Databricks.

     > [!NOTE]
     >
     > Queries must be explicitly saved in Databricks using the **Save** button in the top-right corner of the query editor before they appear in Excel.

4. (Optional) To add query parameters, click **+Add** next to **Parameters**. Click the parameter and enter the **Parameter Name** and **Parameter Value**.
   * For the parameter value, you can either enter a specific value or click the box and arrow button to specify a cell reference. Select a cell or range of cells and click the arrow to automatically fill the parameter value.

5. Under **Output Destination**, choose to import the data to a new sheet or the current sheet. If you import to the current sheet, data starts at the cell reference you enter (by default A1).

6. To preview your query results, click **Run**.

7. Import your results. Choose one of the following:
   * Click **Save and import** to save the query for reuse in the Excel workbook and import the results.
   * Click the down arrow, then click **Import results** to import the results without saving the query. Use this option when you want to continue editing an import.

You can also use custom functions to add query parameters. See [Write SQL](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#func-write-sql).

### <a id="use-template" />Import from a template

A workspace admin or a user with the `CREATE CATALOG` privilege must [set up templates](https://docs.databricks.com/aws/en/integrations/excel/templates.md#set-up-templates) before you can import one. You also need read access on the template group. To import from a template, do the following:

1. In the Databricks Excel Add-in pane, under the **New import** tab, select **Use template** as the **Import method**.
2. Select a template group, then select a template.
3. Under **Imports in this template**, select the imports to bring in. All imports are selected by default.
4. Click **Import**. Each selected import is added to a new sheet and then behaves like any other saved import.

   > [!NOTE]
   >
   > If your workbook already has an import with the same name, the add-in renames the new import by appending a number.

### <a id="filters" />Filter imported data

When you import data by selecting a table or creating a pivot table, you can apply filters to narrow the results.

String filters are case-insensitive and cascading. When you apply more than one filter, the available values for each filter depend on the selections in the filters before it. For example, if you filter by country and then add a filter on city, the city filter offers only cities within the selected country.

To set filters, click **+** next to **Filters**, select the column that you want to apply a filter to, and then enter your filter condition. For filters that require a value, you can do one of the following:

* Enter the value.
* To generate a list of up to 5,000 distinct filter values you can use:
  1. Click **Values**, then **Get filter values**.
  2. Click the down arrow and select one or more values from the list.
* To use a cell reference:
  1. Click **Cells**.
  2. Select a cell or range of cells.
  3. Click the cursor ![Cursor click icon.](https://docs.databricks.com/aws/en/images/product-icons/CursorClickIcon.svg).

The following table describes each available filter and its expected input.

| Filter        | Expected input            | Description                                                                           |
| ------------- | ------------------------- | ------------------------------------------------------------------------------------- |
| `IS NULL`     | None                      | Finds rows where the column value is null.                                            |
| `IS NOT NULL` | None                      | Finds rows where the column value is not null.                                        |
| `EQUALS`      | One number or text string | Finds rows where the column value exactly matches the specified value.                |
| `NOT EQUALS`  | One number or text string | Finds rows where the column value does not match the specified value.                 |
| `STARTS WITH` | One text string           | Finds rows where the column value begins with the specified text.                     |
| `ENDS WITH`   | One text string           | Finds rows where the column value ends with the specified text.                       |
| `CONTAINS`    | One text string           | Finds rows where the column value contains the specified text anywhere in the string. |

### <a id="sort" />Sort imported data

The Databricks Excel Add-in can sort table imports by one or more columns, in ascending or descending order. Sorting isn't available for pivot tables. To sort the results of a SQL query import, add an `ORDER BY` clause to your query.

To add a sort, click ![Plus icon.](https://docs.databricks.com/aws/en/images/product-icons/PlusIcon.svg) next to **Sorting**, then select a column. You can sort by any column in the table, including columns you don't import. Each column can appear in the sort only once, and new sorts are ascending by default.

After you add sorts, you can do the following:

* To switch between ascending and descending order, click ![Sort ascending icon.](https://docs.databricks.com/aws/en/images/product-icons/SortAscendingIcon.svg) or ![Sort descending icon.](https://docs.databricks.com/aws/en/images/product-icons/SortDescendingIcon.svg) next to the column.
* To change the sort priority, drag the column by its ![Drag icon.](https://docs.databricks.com/aws/en/images/product-icons/DragIcon.svg) handle. The add-in sorts by the first column in the list, then by each column after it.
* To remove a sort, click ![Dash icon.](https://docs.databricks.com/aws/en/images/product-icons/DashIcon.svg) next to the column.

The add-in applies sorts after filters and before the row limit. If you set a row limit, the import contains the first rows in sort order. Sorts also apply when you preview or refresh the import, including [scheduled refreshes](https://docs.databricks.com/aws/en/integrations/excel/schedule-refresh.md).

## Calculated fields

A calculated field is a column derived from existing data, such as `profit` computed from `revenue` and `cost`. The Excel Add-in doesn't support creating calculated fields using the **Select data** import method. To add a calculated field, use one of the following methods:

* **Write SQL**: Use the **Write SQL** import method to compute calculated columns with any SQL expression. See [Write SQL queries](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#write-query).
* **Genie One**: Ask Genie One to return your data with the calculated columns you need, then import the results. See [Use Genie One in Microsoft Excel](https://docs.databricks.com/aws/en/integrations/excel/genie.md).

Databricks recommends using Genie One for calculated fields.

## <a id="custom-functions" />Use Databricks custom functions in Excel

The Excel Add-in provides custom functions that you can use in Excel formulas to import data from Databricks.

### <a id="databricks-table" />Select a table

The `DATABRICKS.Table` function imports data from a Unity Catalog table.

**Syntax:**

```text
=DATABRICKS.Table(catalog_name.schema_name.table_name, [column1, ...], [limit])
```

**Parameters:**

* `catalog_name.schema_name.table_name` (required): The fully qualified table name.
* `columns` (optional): An array of column names to import. Omit this parameter to import all columns.
* `limit` (optional): The maximum number of rows to import. Omit this parameter to import all rows, up to the 10 MB limit.

**Example:**

```text
=DATABRICKS.Table("main.default.customers", {"customer_id", "customer_name"}, 100)
```

This formula imports the `customer_id` and `customer_name` columns from the `main.default.customers` table, limited to 100 rows.

### <a id="func-write-sql" />Write SQL

The `DATABRICKS.SQL` function runs a SQL query that uses query parameters and returns the results.

**Syntax:**

Specify parameters using values.

```text
=DATABRICKS.SQL("query_text", {parameter1_name, parameter1_value; ...})
```

Specify parameters using a cell range. Define the name and value parameters in cells that are in the same row.

```text
=DATABRICKS.SQL("query_text", {param_name_cell: param_value_cell; ...})
```

**Parameters:**

* `query_text` (required): The SQL query to run.
* `parameters` (required): A mapping of parameter values to substitute into the query.

**Example:**

```text
=DATABRICKS.SQL("SELECT * FROM samples.bakehouse.sales_suppliers WHERE longitude > :long_param AND latitude > :lat_param LIMIT 10", {"long_param",20; "lat_param",10})

=DATABRICKS.SQL("SELECT * FROM samples.bakehouse.sales_suppliers WHERE city = :city", M4:N4)
```

This formula runs a query that filters sales data by `longitude` and `latitude`, using the provided parameter values.

## <a id="manage-queries" />Manage queries

Manage your existing imports from the Imports page.

### <a id="edit-query" />Edit an existing import

To edit an existing import:

1. In the Databricks Add-in pane in Excel, click the **Imports** tab.
2. Find the import you want to edit.
3. Click the three-dot menu next to the import.
4. Click **Edit** to edit your import.

### <a id="refresh" />Refresh data

The Excel Add-in does not refresh data automatically. How you refresh data depends on how you imported it. Data imported using an import method (select a table, write a SQL query, or create a pivot table) refreshes from the **Imports** tab. Data imported using a custom function must be recalculated.

Update imports with the latest values from Databricks. The Add-in runs the original query or table selection again and updates your worksheet with fresh data:

* To refresh a single import:
  1. In the Databricks Add-in pane in Excel, click the **Imports** tab.
  2. Click ![Refresh icon.](https://docs.databricks.com/aws/en/images/product-icons/RefreshIcon.svg) refresh next to the import you want to refresh.
* To refresh all imports:
  1. Click **Refresh All** in the Databricks Add-in pane.

> [!IMPORTANT]
>
> When refreshing data, the Excel Add-in clears all existing data in the specified table and reloads the newest data from Databricks. Any custom columns you added to the table are deleted during the refresh process.

Data imported from custom functions, such as `DATABRICKS.Table` and `DATABRICKS.SQL`, does not refresh when you reopen a workbook. To refresh data imported from custom functions, sign in to the Databricks Add-in, then either recalculate the workbook or change a value the custom function references.

## Sharing implications

When you share an Excel workbook that contains Databricks data, consider the following data access and security implications:

### Visibility to imported data

When a recipient refreshes an import, the Add-in uses the recipient's Unity Catalog permissions. If they do not have access to the underlying data, the refresh fails.

For workbooks where data privacy is a concern, you can use the following workaround:

1. Create a workbook with all necessary formulas and imports.
2. Delete the imported data from the sheet.
3. Share the workbook with the recipient.
4. Have the recipient refresh the data.

The recipient only sees data they have access to based on their Unity Catalog permissions.

### Access to workspaces and data assets

* Users without access to the Unity Catalog objects referenced in the workbook can't refresh the data. To refresh data, users must have read permissions on the underlying tables and views in Unity Catalog.
* Users must have access to the underlying table in Databricks to edit existing imports.

### Query visibility

Users with edit access to the workbook can view the queries used to generate the data through the Databricks Add-in, even if they don't have access to the underlying data in Unity Catalog.

## <a id="share-as-template" />Share saved imports

To share a reusable set of imports, [create a template](https://docs.databricks.com/aws/en/integrations/excel/templates.md#create-template) from your saved imports. A template stores only the query definitions, not the imported data, so each user runs the queries with their own Unity Catalog permissions.

To share a whole workbook, including its saved imports and imported data, do one of the following:

* Share the local file with another user. The recipient can rename the file and see the saved queries.
* On SharePoint, share the workbook with another user. When another user downloads the file, the saved imports are preserved.

See [Sharing implications](https://docs.databricks.com/aws/en/integrations/excel/query-data.md#sharing-implications) for data access and security considerations.

## <a id="limitations" />Limitations

* **Custom functions**: For custom functions, query results are limited to 25 MiB due to limitations of the SQL execution API.
* **Data loading**: Data loading might fail if any cell in the workbook is in edit mode.
* **Excel Desktop row limit**: Excel Desktop supports a maximum of 1,048,576 rows per sheet.
* **Excel for the web file size limit**: Excel for the web supports a maximum workbook file size of approximately 25 MB for viewing and editing.
* **Live query performance**: With **Live query** on, each pivot edit runs a new query against your SQL warehouse. Results are not cached locally, so frequent edits on large pivots can add latency and warehouse cost.
* **Template imports**: When you import a template, the original import's scheduled refresh settings aren't carried over. To refresh the imported data automatically, [schedule a refresh](https://docs.databricks.com/aws/en/integrations/excel/schedule-refresh.md) after importing. See [Templates in Excel](https://docs.databricks.com/aws/en/integrations/excel/templates.md).
