In this Power Bi tutorial, we will learn what is Power BI If a null statement and how can we check the null value is presented in a column with examples. In addition, we will also learn to use the power query editor to check null values in Power BI. Moreover, we also cover the below headings:
- Power BI if null then 0
- Power BI if a null measure
- Power BI if null then Blank
- Power BI if null then else
Power BI if null statement
Power BI IF statement is a logical statement that checks a condition and returns the first value as True else it returns the second value as False.
The Power BI IF statement syntax:
IF(<logical_test>, <value_if_true>[, <value_if_false>])
In the following, we will see how to work with the Power BI IF statement null with different examples.
Power BI if null then 0
Let us see how to display the zero values for the null values using the Power Bi IF function in the Power BI report.
In this example, we will use the below Stocks table data as a data source, and if any of the rows presented null values then it displays 0 else it returns a blank value.
- Log in to the Power Bi desktop and load data using the get data option. Once the data has been loaded, Click on the new column option under the modeling tab and apply the below-mentioned formula:
Text Null = IF(not(isblank(Stocks[Symbol])),BLANK(),"0")
Where,
- Text Null = Newly calculated column
- Stocks = Table Name
- Symbol = Existing Column Name
In the below screenshot, we can see that if the Symbol column has null values then it returns the value as 0 else it returns a blank value based on the condition applied:
This is how to display the zero values for the null values using the Power Bi IF function in Power BI.
Power BI if a null measure
Let us see how to find the null value using the Power Bi DAX function in Power BI.
In this example, we will find the null values for the data below and if the selected column contains null values then we will display the null value else we will display the column value in the Table visual.
Log in to the Power Bi desktop and load data using the get data option. Once the data has been loaded, select the new measure option and use the below formula:
Table Measure = IF(SELECTEDVALUE(Stocks[Symbol])=BLANK()," Null Value",SELECTEDVALUE(Stocks[Symbol]))
Where,
- Table Measure = New Measure name
- SELECTEDVALUE = Function Name
- Stocks = Table Name
- Symbol = Column Name
Select the table visual from the visualization, drop the Stock name, Symbol, and the created measure value into the columns section as shown below:
The screenshot below displays the values in the table visual based on the condition applied. If the column has a null value then it returns a null value else the presented value in the column.
This is how to find the null value using the Power Bi DAX function in Power BI.
Power BI if null then Blank
Here we will see how can we find the null value using the Power Bi If function in Power BI.
In this example, we will find the null value for the stock shares column as highlighted below, if the stock has zero or null shares then it returns a blank value else it returns the stock shares value in matrix visual.
Open the Power Bi desktop and load data using the get data option. Once the data has been loaded, Click on the new measure option under the modeling tab and apply the below-mentioned formula:
Matrix Measure = IF(SELECTEDVALUE(Stocks[Shares])=BLANK(),"Blank",SELECTEDVALUE(Stocks[Shares]))
Where,
- Matrix Measure = New Measure name
- SELECTEDVALUE = Function Name
- Stocks = Table Name
- Shares= Column Name
Select the matrix visual from the visualization, drop the Stock name in the row section, shares the field, and the created measure value into the values section as shown below:
In the below screenshot, we can see that the matrix visually displays the result value based on the applied condition.
This is how to find the null value using the Power Bi If function in Power BI.
Read Power BI Merge Two Tables without Duplicates
Power BI if null then else
Here we will see how to check the null values using the Power Query editor in Power BI.
In this example, we will check the null value for the stock shares field, if any of the rows have null values then we will display the null value else it returns the stock shares value.
- Load the data into the Power Bi desktop, and Select the Home tab -> to transform data option, It will automatically redirect to the Power Query editor.
- select the Add Column-> Custom column in the power query editor. In the custom column pop-up window use the below formula and click the ok button.
if(([Shares])=null) then "Null Value" else[Shares]
- In the below screenshot, we can see that the newly added custom column displays the value based on the condition applied.
- If the Symbol column contains the text data type value then it returns the null value else it returns the stock shares value.
- Click on Close & Apply under the home tab, so that the changes will be reflected on the Power Bi desktop.
= Table.AddColumn(#"Removed Columns2", "Custom", each if(([Shares])=null) then "Null Value" else[Shares])
This is how to check the null values using the Power Query editor in Power BI.
In this Power Bi tutorial, we have learned what is Power BI If a null statement and how can we check the null value is presented in a column with examples. In addition, we also learned to use the power query editor to check null values in Power BI. Moreover, we also covered the below headings:
- Power BI if null then 0
- Power BI if a null measure
- Power BI if null then Blank
- Power BI if null then else
You may like the following Power Bi tutorials:
- How to Check IF Text is NULL in Power BI
- Power BI Measure If Text
- Power BI Conditional Formatting Based on Text
- Power BI Switch Multiple Conditions
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com