How to Add a Formula Field in Looker Studio

Adding a formula field (also known as a calculated field) in Looker Studio is a powerful way to customize your data by creating new metrics or dimensions based on existing data. A formula field allows you to perform calculations, apply conditions, and transform data directly in Looker Studio without modifying the original data source. From my experience, this feature is essential when you need to create customized metrics or KPIs that aren’t readily available in your dataset.

Here’s a step-by-step guide on how to add a formula field in Looker Studio:

Step-by-Step Guide to Adding a Formula Field #

1. Open Your Report in Looker Studio #

  • Start by opening the report where you want to add the formula field.
  • If you haven’t yet connected a data source, you’ll need to do so by clicking Add Data and selecting your desired data source.

2. Access the Data Panel #

  • Once inside your report, click on the Data Panel on the right side of the screen.
  • In the data panel, you will see a list of fields available from your data source.

3. Create a New Field #

  • Scroll down to the Available Fields section.
  • Click on the + Add a Field button at the bottom of the data panel.

4. Name the Formula Field #

  • A new window will pop up titled Create Field.
  • In the field name box at the top, enter the name for your new calculated field. This name should describe the purpose of the field (e.g., "Revenue per User" or "Conversion Rate").

5. Write the Formula #

  • In the Formula box, write your formula using the available fields and functions.

  • Looker Studio provides a range of mathematical, string, date, and logical functions you can use to create custom formulas. For example:

    • Basic Math: You can perform basic arithmetic like addition, subtraction, multiplication, and division.
      Profit = Revenue - Cost
    • String Functions: You can concatenate or manipulate text fields.
      Full Name = CONCAT(FirstName, " ", LastName)
    • Date Functions: Perform calculations on dates.
      Days Since Purchase = DATE_DIFF(TODAY(), PurchaseDate)
    • Conditional Statements (CASE): You can apply conditional logic using the CASE function.
      CASE
      WHEN Sessions > 100 THEN "High"
      ELSE "Low"
      END
  • Looker Studio provides a dropdown list of available fields and functions that you can use to build your formula. As you type, the system will automatically suggest fields and functions to help you construct the formula.

6. Validate the Formula #

  • Once you’ve written your formula, click Validate to check for errors. If there’s a syntax error or an issue with your formula, Looker Studio will highlight the problem and provide feedback.
  • Correct any errors if needed and validate again until the formula is correct.

7. Save the Formula Field #

  • After validating the formula, click Save to add the field to your report.
  • The new calculated field will now appear in the Available Fields list in the data panel and can be used just like any other field in your report.

8. Add the Formula Field to Your Visualization #

  • To use your new formula field, drag it from the data panel and drop it into your chart or visualization. You can use it in the same way you would use any standard field from your data source.

Example Formula Fields #

Here are some examples of commonly used formula fields:

  • Revenue Per User:

    Revenue Per User = Revenue / Users
  • Conversion Rate:

    Conversion Rate = (Conversions / Sessions) * 100
  • Total Revenue with Tax:

    Total Revenue = Revenue * (1 + TaxRate)
  • Text Field Manipulation (Combining First and Last Name):

    Full Name = CONCAT(FirstName, " ", LastName)
  • Case Statement Example:

    CASE
    WHEN Sessions > 500 THEN "High Traffic"
    WHEN Sessions BETWEEN 100 AND 500 THEN "Medium Traffic"
    ELSE "Low Traffic"
    END

Key Functions to Use in Formula Fields #

  • Math Functions: SUM(), AVG(), MIN(), MAX(), COUNT()
  • String Functions: CONCAT(), LOWER(), UPPER(), REGEXP_EXTRACT()
  • Date Functions: DATE_DIFF(), TODAY(), YEAR(), MONTH()
  • Logical Functions: IF(), CASE(), AND(), OR()
  • Aggregation: Use functions like SUM, COUNT, or AVERAGE to aggregate data across rows.
    • Example: SUM(Revenue) or AVG(Sessions)

Tips for Using Formula Fields in Looker Studio #

  • Use Descriptive Names: When creating new formula fields, use descriptive names that clearly convey the purpose of the field.
  • Test Your Formulas: Always test your formula fields in your visualizations to ensure they are calculating correctly before using them extensively in reports.
  • Simplify Complex Formulas: If you have a complex formula, break it into multiple smaller formula fields to make it easier to debug and understand.
  • Optimize for Performance: Avoid overly complex formulas or unnecessary calculations that can slow down your report. If possible, pre-process data in your source system (e.g., Google Sheets, BigQuery) before using it in Looker Studio.

Conclusion #

Adding a formula field in Looker Studio allows you to customize your data by creating new metrics and dimensions tailored to your reporting needs. Whether you’re calculating percentages, transforming text, or applying conditional logic, formula fields provide powerful flexibility within your reports. By following the steps outlined above, you can easily enhance your Looker Studio dashboards with dynamic, custom data fields.

For more guidance on customizing reports, check out How to Use Calculated Fields in Looker Studio or explore How to Create a Looker Studio Dashboard for insights on building your first report.

Published