University > Looker Studio course > IF function: How to use & example

IF function: How to use & example

Discover how to use the IF function in Looker Studio to apply conditional logic in reports. Learn syntax, use cases, and practical examples.

Formulas

The IF function in Looker Studio (formerly Google Data Studio) is one of the most useful tools for adding logic and flexibility to your reports. It allows you to define conditions and return different values depending on whether those conditions are true or false. By doing so, you can create dynamic calculated fields, classify data, and adapt your dashboards to specific business rules or KPIs.

What is the IF function

The IF function tests a condition and returns one result if the condition is true, and another result if it is false.
It works similarly to IF statements used in programming or spreadsheets and is highly optimized for quick evaluation in Looker Studio.

Syntax:

IF(condition, value_if_true, value_if_false)

  • condition: a Boolean expression that can be evaluated as true or false.
  • value_if_true: the result returned if the condition is true.
  • value_if_false: the result returned if the condition is false.

Both results can be static values, text labels, or even other calculated expressions.

How it works

When Looker Studio evaluates an IF statement, it checks the logical condition you specify.
If the condition is met, it outputs the “true” value; otherwise, it returns the “false” value.
This makes IF an essential function for conditional logic, data segmentation, and automated classification inside reports.

Example:

IF(order_total > 100, "High Value", "Low Value")

This formula will return “High Value” if the order total is greater than 100, and “Low Value” otherwise.

Using nested IF statements

You can combine multiple IF statements to handle more than two outcomes. This technique, known as “nesting,” allows you to build detailed classification systems.

Example:

IF(order_total > 100, "High",
 IF(order_total > 50, "Medium", "Low")
)

Here, the function first checks if the order total exceeds 100. If not, it checks whether it’s greater than 50, returning “Medium” or “Low” accordingly.

Nested IFs are especially powerful for building multi-level rules directly inside Looker Studio calculated fields.

Common Use Case: Customer Segmentation

A common application of the IF function is to segment customers based on their activity or total revenue.
For instance, you can create a calculated field called “Customer Lifetime Value Tier” to assign customers to tiers like Bronze, Silver, Gold, or Platinum.

Example:

IF(lifetime_revenue < 1000, "Bronze",
 IF(lifetime_revenue >= 1000 AND lifetime_revenue < 5000, "Silver",
   IF(lifetime_revenue >= 5000 AND lifetime_revenue < 10000, "Gold",
     IF(lifetime_revenue >= 10000, "Platinum", "N/A")
   )
 )
)

You can even refine this logic by filtering inactive customers first:

IF(weeks_since_last_order > 52 OR orders_count < 2, "Inactive",
 IF(lifetime_revenue < 1000, "Bronze",
   IF(lifetime_revenue >= 1000 AND lifetime_revenue < 5000, "Silver",
     IF(lifetime_revenue >= 5000 AND lifetime_revenue < 10000, "Gold",
       IF(lifetime_revenue >= 10000, "Platinum", "N/A")
     )
   )
 )
)

This ensures inactive users are flagged before being assigned to a tier.
The result is a dynamic classification system that updates automatically as your data changes.

Limitations and Best Practices

  • Binary output: IF handles only two outcomes (true or false). Use CASE for more complex branching.
  • Data type consistency: ensure that the true and false results return values of the same type (both text, numbers, or Boolean).
  • Keep conditions clear: use simple expressions and combine multiple conditions with AND or OR only when necessary.
  • Performance: prefer simple IFs to deeply nested ones when possible; they are faster and easier to maintain.

Summary

The IF function is one of the most direct and powerful tools in Looker Studio for adding logic to your data.
It lets you test conditions, assign values dynamically, and customize your reports to adapt to specific scenarios.
Whether you are labeling transactions, segmenting customers, or flagging anomalies, IF helps you build calculated fields that make your dashboards smarter and more interactive.

More Functions to Explore in Looker Studio

  • CASE – Handle multiple outcomes in a single expression
  • IFNULL – Replace null values with a default value
  • REGEXP_MATCH – Match text patterns using regular expressions
  • DATETIME_DIFF – Calculate time differences
  • CEIL – Round numbers up to the nearest integer