Notification

This article is about Looker Studio. For Looker documentation, visit https://cloud.google.com/looker/docs/intro.

Trang bạn đã yêu cầu hiện không có sẵn bằng ngôn ngữ của bạn. Bạn có thể chọn ngôn ngữ khác ở cuối trang hoặc dịch nhanh mọi trang web sang ngôn ngữ mà bạn chọn bằng cách sử dụng tính năng dịch được tích hợp sẵn trong Google Chrome.

NULLIF

Returns null if the input matches an expression, otherwise returns the input.

Use NULLIF to selectively replace a specific value in your data with NULL. This can be helpful in situations where a particular value represents missing or invalid data, and you want to explicitly mark it as NULL for further analysis or processing.

Sample usage

Replace -1 in the Discount field with NULL.

NULLIF(Discount, -1)

Syntax

NULLIF(input_expression, expression_to_match)

Parameters

input_expression

The expression to evaluate. You can use any valid expression as the input_expression.

expression_to_match

NULLIF compares expression_to_match to input_expression. If the two are equal, NULLIF returns null, otherwise it returns the input_expression. You can use any valid expression as the expression_to_match.

Example

Suppose you want to calculate the average discount given to your customers. Your application represents "no discount" as -1. The formula AVG(Discount) will count -1 and return an incorrect result. To avoid this, you can convert those -1s to NULLS. To do this, create a new field called, for example, Discount With Nulls:

NULLIF(Discount, -1)

This formula can be read, "If the Discount field is -1, return null, otherwise return Discount."

You can then calculate the average discount ignoring orders with no discount:

AVG(Discount With Nulls)

Thông tin này có hữu ích không?

Chúng tôi có thể cải thiện trang này bằng cách nào?
true
What's new in Looker Studio?

Learn about new features and recent changes. Looker Studio release notes live on Google Cloud.

Search
Clear search
Close search
Main menu
11822292024260568247
true
Tìm kiếm trong Trung tâm trợ giúp
true
true
true
true
true
102097
false
false