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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
heidibb
Helper IV
Helper IV

Count non-blank cells across a range of columns

Hello,

I am trying to create a column that basically counts the number of columns for each row that are not blank. See image. The value i'm looking for would be 4 for the top few rows since ther are 4 columns that are not null.

Is there a way to do this in query editor?Capture.JPG

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@heidibb

Yes, if you click Custom Column on the ribbon, in the dialog box enter this in the formula section:

=List.NonNullCount(Record.FieldValues(_))

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

11 REPLIES 11
sohananahid
Post Partisan
Post Partisan

Hi,

I had a similar issue where i need to count 5 different Columns with non blank values that indicate some actions were taken for specific MoC. So, when I select a MOC - i need to see the count of actions taken. I did the following DAX : a calculated Col in the table

Count Action =

VAR Col1nonblank = IF(ISBLANK('Table1'[Action 1]), 0, 1)

VAR Col2nonblank = IF(ISBLANK('Table1'[Action 2]), 0, 1)

VAR Col3nonblank = IF(ISBLANK('Table1'[Action 3]), 0, 1)

VAR Col4nonblank = IF(ISBLANK('Table1'[Action 4]), 0, 1)

VAR Col5nonblank = IF(ISBLANK('Table1'[Action 5]), 0, 1)

RETURN Col1nonblank + Col2nonblank + Col3nonblank + Col4nonblank + Col5nonblank

-A data card visual-> sum of -> Count Action

Just sharing this in case it helps someone else! Cheers! 🙂

Thank you so much!  This worked perfectly for me, much appriciated!

OwenAuger
Super User
Super User

@alicek 

I would suggest something like this in place of the above code, using List.Select to select the empty strings:

=List.Count(List.Select(Record.FieldValues(_), each _="" ) )

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Amazing, thank you @OwenAuger !! 

 

I tried to combine what you sent above with the List.Range, because I need to count the number of blanks in the first five rows. So I tried various combinations:

List.Count(List.Range(Record.FieldValues(_), 1, 5, each _=""))

List.Count(List.Range(Record.FieldValues(_), each _="", 1, 5))

List.Count(List.Select(Record.FieldValues(_), 1, 5, each _=""))

List.Count(List.Select(Record.FieldValues(_), each _="", 1, 5))

 

None of them worked... do you think it's possible to do? Perhaps I need to nest a List.Select within a List.Range or vice versa?

Whoops, nevermind, got it! I had to nest them. Just in case this ever helps anyone else, here is what the final formula looked like: 

List.Count(List.Range(List.Select(Record.FieldValues(_), each _=""), 1, 5))

 

Thanks @OwenAuger !

OwenAuger
Super User
Super User

@heidibb

Yes, if you click Custom Column on the ribbon, in the dialog box enter this in the formula section:

=List.NonNullCount(Record.FieldValues(_))

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

Dear 

 

Thank you for sharing the custom column DAX for List.NonNullCount(Record.FieldValues(_)) is working but 178,232 row showing blank out of 672,746 Rows. i cross-checked the information available. i can not why its showing blank. can you please help me to solve this problem  

 

Regards

Munish Bawa

What if I don't want to include every column in the count, what if I only want to count columns 2 - 8?

@jtolmen 

If you want to select columns by position, you could wrap List.Range around Record.FieldValues. For example, this would be the Custom Column Formula in the Custom Column dialog box:

=List.NonNullCount(List.Range(Record.FieldValues(_),1,7))

Regards

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

@jtolmenand @OwenAuger thanks for your help on this - it also helped me! 

Instead of null, my cells are blank. Is there an equivalent M formula for that? 

I can't make them null instead of blank, because I am also creating a custom column that concatenates their values. If I make any of the cells null, the whole cell becomes null for some reason. 

@alicek 

If you are wanting to count nonempty strings, you could write something like this, using List.Select:

= List.Count( List.Select( Record.FieldValues(_), each _ <> "") )

Does that give you the expected result?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.