Returns the logarithm of a positive number.

The mathematical base that the `LOG` function uses depends on the following factors:

If the underlying dataset can perform the calculation, then the `LOG` function uses base-*e*.

`LOG` uses base 2 whenever Data Studio performs the calculation itself instead of letting the underlying dataset run the calculation. For example, Data Studio calculates the formula itself in the
following situations:

- You use `LOG` in a calculated field on a data source that doesn't support performing the calculation, such as Bigtable or Google Ads.
- You use `LOG` in a calculated field on a [blended data source](https://docs.cloud.google.com/data-studio/how-blends-work.md.txt), even when the original data sources use base-*e* connectors.
- Your formula combines `LOG` with a function that the underlying data source doesn't support directly, such as `LOG(MEDIAN(Price))` on Spanner.

The following table summarizes the connectors and situations that use base-*e* and base-2:

| Connectors that use Base *e* (natural logarithm) | Connectors and situations that use Base 2 |
|---|---|
| - Amazon Redshift - Apigee - BigQuery - Extract Data - Looker - Microsoft Excel - Microsoft SQL Server - MySQL / Cloud SQL for MySQL - PostgreSQL - Google Sheets - Spanner | - Bigtable - Campaign Manager 360 - Community connectors - CSV file upload - Display \& Video 360 - Google Ad Manager 360 - Google Ads - Google Analytics - Search Ads 360 / Search Console - Cloud Storage - YouTube Analytics - Blended data sources - Formulas that Data Studio calculates itself |

## Calculate a logarithm with a custom base

For base-10 logarithms, use the [`LOG10`](https://docs.cloud.google.com/data-studio/log10.md.txt) function,
which uses base 10 across all connectors.

To calculate a logarithm with a
consistent custom base <var translate="no">B</var> across any connector or blend, use the
change-of-base formula:
`LOG10(X) / LOG10(B)`.

For example, use
`LOG10(X) / LOG10(2.718281828459045)` for base *e* or
`LOG10(X) / LOG10(2)` for base 2.

> [!NOTE]
> **Note:** Data Studio doesn't support a two-argument `LOG(X, base)` syntax to specify a custom base.

## Sample usage

`LOG(256)`

## Syntax

`LOG( X )`

### Parameters

- `X`: a positive number, field, or expression that evaluates to a positive number.

## Examples

The following table compares `LOG` outputs for base-*e* and base-2 connectors:

| Example formula | Input | Base-*e* output | Base-2 output |
|---|---|---|---|
| `LOG(My field)` | 1 | 0 | 0 |
| `LOG(My field)` | 2.718281828459045 | 1 | 1.442695041 |
| `LOG(My field)` | 128 | 4.852030264 | 7 |

## Related resources

- [Calculated fields](https://docs.cloud.google.com/data-studio/about-calculated-fields.md.txt)
- [LOG10](https://docs.cloud.google.com/data-studio/log10.md.txt)
- [Data Studio function list](https://docs.cloud.google.com/data-studio/function-list.md.txt)