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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
WALEED
Advocate II
Advocate II

Count ALL Populated Cells in a Whole Table

It's baffling how much time I've spent trying to solve this:

 

What I simply have is:

 

TAGVALUE1VALUE2
BOB001A4
BOB002F 
BOB003 7

 

What I simply want is a count from the whole table like COUNTA(Table) = 7

 

Defining columns by name in the formula is not an option because I have 30 tables with continuously changing column names, I know; exciting stuff 😞

 

This is eventually used to calculate how complete a table is, using the table above as an example; (7/9)x100

 

I'm looking for a solution in either Power BI or Power Query

1 ACCEPTED SOLUTION

I have a feeling you can, so I did some research - the solution turned out to be pretty simple.

You have to do some hacking in the Power Query "Advanced Editor".

Let's say the original table (with 3 columns) is called "T1" in the M script, then you can add two more lines to add the two calculated columns you wanted:

 

let

     ...

    , T2 = Table.AddColumn(T1, "COUNT ACTUAL", each List.NonNullCount( Record.FieldValues(_) ) )
    , T3 = Table.AddColumn(T2, "COUNT EXPECTED", each -1 + List.Count( Record.FieldValues(_) ) )

in

    T3

 

View solution in original post

5 REPLIES 5
DAX0110
Resolver V
Resolver V

If you unpivot all the columns (in Power Query),  you will obtain a single column that contains all the table cells.  Then, it's a simple matter of counting which ones are non-blank.

 

Do you know a trick I can use to do this for example: (Adding Columns)

TAGVALUE1VALUE2COUNT ACTUALCOUNT EXPECTED
BOB001A433
BOB002F 23
BOB003 723

 

I'd love to keep the table for re-use.

 

If not, using this query as a source for a new query (unpivot) might be the way to go. And I'll accept the answer.

I have a feeling you can, so I did some research - the solution turned out to be pretty simple.

You have to do some hacking in the Power Query "Advanced Editor".

Let's say the original table (with 3 columns) is called "T1" in the M script, then you can add two more lines to add the two calculated columns you wanted:

 

let

     ...

    , T2 = Table.AddColumn(T1, "COUNT ACTUAL", each List.NonNullCount( Record.FieldValues(_) ) )
    , T3 = Table.AddColumn(T2, "COUNT EXPECTED", each -1 + List.Count( Record.FieldValues(_) ) )

in

    T3

 

You, sir, ARE A GENIUS!

 

What I have in place of nulls are blanks; I think it'll be easy to resolve this last part. If you have the answer, please add it on top so it may benefit others. Kudos to you.

That's the one amendment (to search for blanks rather than nulls):

COUNTACTUAL = Table.AddColumn(#"Removed Columns", "COUNT ACTUAL", each + List.Count(List.Select(Record.FieldValues(_),each _ <> ""))),

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.