Stay organized with collections
Save and categorize content based on your preferences.
Use IFNULL to replace NULL values in your data with a more suitable or meaningful value. This can be helpful when you want to avoid displaying NULLs in your charts or when you need a specific value for further calculations.
Sample usage
IFNULL(Discount, 0)
Syntax
IFNULL( input_expression, null_result )
Parameters
input_expression -- The expression to evaluate. You can use any valid expression as the input_expression.
null_result -- The value to return if input_expression is null. If input_expression is not null, IFNULL returns the input_expression. You can use any valid expression as the null_result.
Example
Calculate the average discount given to your customers, including orders that received no discount. However, your application sometimes represents "no discount" as null rather than 0.
The formula AVG(Discount) won't include null discounts. You'll need to convert those nulls to zero. To do this, create a new field called, for example, Discount No Nulls:
IFNULL(Discount, 0)
This formula can be read, "If the Discount field is null, return 0, otherwise return Discount."
You can then calculate the average discount including orders with no discount:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# IFNULL\n\nUse `IFNULL` to replace NULL values in your data with a more suitable or meaningful value. This can be helpful when you want to avoid displaying NULLs in your charts or when you need a specific value for further calculations.\n\nSample usage\n------------\n\n`IFNULL(Discount, 0)`\n\nSyntax\n------\n\n`IFNULL( `\u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003enull_result\u003c/var\u003e` )`\n\n### Parameters\n\n- **`input_expression`** -- The expression to evaluate. You can use any valid expression as the \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e.\n\n- **`null_result`** -- The value to return if \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e is null. If \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e is not null, `IFNULL` returns the \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e. You can use any valid expression as the \u003cvar translate=\"no\"\u003enull_result\u003c/var\u003e.\n\nExample\n-------\n\nCalculate the average discount given to your customers, including orders that received no discount. However, your application sometimes represents \"no discount\" as null rather than 0.\n\nThe formula `AVG(Discount)` won't include null discounts. You'll need to convert those nulls to zero. To do this, create a new field called, for example, **Discount No Nulls**:\n\n`IFNULL(Discount, 0)`\n\nThis formula can be read, \"If the **Discount** field is null, return 0, otherwise return **Discount**.\"\n\nYou can then calculate the average discount including orders with no discount:\n\n`AVG(Discount No Nulls)`"]]