Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Hoping
Helper II
Helper II

Check for a Column with all null values

I wat to check if an entire column has null values and if yes, add another column with value "YES NULL" else "NO NOT NULL" repeating in DAX.
ISBLANK does it for every row. But I want to check the entire column.

The check for nulls needs to happen after the filters are applied.

 

 

 

VAR TABLE1 = 
CALCULATETABLE(
                             SUMMARIZE(  TAB[Col1],
                                         TAB[Col2],
                                         TAB[Col3]
                                       ),  
               KEEPFILTERS(FILTERTABLE)
               )

VAR NumberofRows = COUNTROWS(TABLE1)
VAR NumberofNullRows = COUNTBLANK(TABLE1[Col3])
VAR Check = IF(NumberofRows = NumberofNullRows, "YES ALL NULL", "NO NOT NULL")
VAR TABLE2 = ADDCOLUMNS(TABLE1, "Col4", Check)	
EVALUATE TABLE2

 

 

I think above code is failing beause Variable Check in the above code is a single value. How can I make it into a list so that it can be added to the column?

1 ACCEPTED SOLUTION
some_bih
Super User
Super User

Hi @Hoping in general to check if column contains null, one possible solution is

Is_Null_Column =
IF(
COUNTROWS(<YourTableName>) = COUNTBLANK(<YourTableName>[YourColumnName]),
"Yes:NULL",
"No:NOT NULL"
)

 

Did I answer your question? Mark my post as a solution! Kudos Appreciated!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






View solution in original post

6 REPLIES 6
Alef_Ricardo_
Resolver II
Resolver II

You are correct that the `Check` variable in your code is a single value, and you cannot add a single value to a column. Instead, you can use the `Check` variable as an input to the `ADDCOLUMNS` function to create a new column with the desired values. Here's an example of how you can modify your code to achieve this:

 

```
VAR TABLE1 = CALCULATETABLE( SUMMARIZE( TAB[Col1], TAB[Col2], TAB[Col3] ), KEEPFILTERS(FILTERTABLE) )
VAR NumberofRows = COUNTROWS(TABLE1)
VAR NumberofNullRows = COUNTBLANK(TABLE1[Col3])
VAR Check = IF(NumberofRows = NumberofNullRows, "YES ALL NULL", "NO NOT NULL")
VAR TABLE2 = ADDCOLUMNS(TABLE1, "Col4", Check)
EVALUATE TABLE2
```

In this modified version of your code, the `Check` variable is used as an input to the `ADDCOLUMNS` function, which creates a new column `Col4` in `TABLE2` with the value of `Check` for each row. This should give you the desired result of a new column with the value `"YES ALL NULL"` if all values in `Col3` are null, and `"NO NOT NULL"` otherwise.

 

I hope this helps! Let me know if you have any further questions. 😊

 

some_bih
Super User
Super User

Hi @Hoping in general to check if column contains null, one possible solution is

Is_Null_Column =
IF(
COUNTROWS(<YourTableName>) = COUNTBLANK(<YourTableName>[YourColumnName]),
"Yes:NULL",
"No:NOT NULL"
)

 

Did I answer your question? Mark my post as a solution! Kudos Appreciated!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






@some_bih  The check for NULL / BLANKS is after filtering.  How can keep the filters in the above code ?

Hi @Hoping the solution is for column, all rows in single column to be checked if there are NULL





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Yes, that is one way to check if a column contains all null values. The `Is_Null_Column` measure you provided compares the number of rows in the table with the number of blank values in the specified column. If these two values are equal, it means that all values in the column are null, and the measure returns `"Yes:NULL"`. Otherwise, it returns `"No:NOT NULL"`.

Thank you for sharing your solution! 😊

Hi @Hoping If this is solution, please accept it so other member of community could use it. Thank you





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors