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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Dicken
Post Prodigy
Post Prodigy

Counting nulls


Hi, 
    counting null values,    i have; 

= let alist = 
{1,2,2,"a",null, null, 2,"a",3,2,null, "a"} 
in 
List.Count( alist) - List.NonNullCount( alist)


or 

= let alist = 
{1,2,2,"a",null, null, 2,"a",3,2,null, "a"} 
in 
List.Count( List.Select( alist, (x)=> 
 Value.Is(x, type null)) )



woud anyone like to suggest differerent / better way  ?  

2 ACCEPTED SOLUTIONS
Parchitect
Impactful Individual
Impactful Individual

Hi @Dicken,

For pure null values, I would keep your first approach. It is probably the cleanest and easiest to read:

let
    alist = {1,2,2,"a",null, null, 2,"a",3,2,null, "a"}
in
    List.Count(alist) - List.NonNullCount(alist)

 

List.NonNullCount is built to count non-null items, so total count minus non-null count gives the null count.

 

View solution in original post

slorin
Super User
Super User

List.Accumulate(alist, 0, (i,x) => i + Number.From(x=null))
List.Sum(List.Transform( alist, each Number.From(_=null)))

 

View solution in original post

13 REPLIES 13
slorin
Super User
Super User

You don't need List.Accumulate, just List.Transform

List.Transform( alist , each Number.From(_ = null))

 

I know, I just liked it. 

Dicken
Post Prodigy
Post Prodigy

a take on the accumulate version, so not to count but show where null;

= let alist = {"a",1,null, null,"a",3,"b"} 
, t = "a" 
in   List.Accumulate( alist, {}  , (s,c)=> 
  s & { Number.From( c = null ) } )
slorin
Super User
Super User

List.Accumulate(alist, 0, (i,x) => i + Number.From(x=null))
List.Sum(List.Transform( alist, each Number.From(_=null)))

 

penny dropped,  coerecing  true / false to 1 ,0   

really like that, only now i have to look into why it works as 
Number.From(_  = null) 
Number.From(_ ) = null)
are not the same 

AlienSx
Super User
Super User

let
    fx = (x, y) => if List.Count(x) = 0 then y else @ fx(List.Skip(x), y + Number.From(x{0} = null))
in
    fx({1, 2, 2, "a", null, null, 2, "a", 3, 2, null, "a"}, 0)
Dicken
Post Prodigy
Post Prodigy

just to add recgarding the count , remove nul,   i did say count nulls. 

My bad. I removed my answer as a solution. You could do this...

let 
    alist = 
    {1,2,2,"a",null, null, 2,"a",3,2,null, "a"} 
in 
    List.Count( alist ) - List.Count( List.RemoveNulls( alist ))




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

Proud to be a Super User!





slorin
Super User
Super User

Hi,

List.Count(List.PositionOf(alist, null, Occurrence.All))

Stéphane

Thanks to all responses,  always nice to see what I had not thought of.

jgeddes
Super User
Super User

This should work too...

let 
    alist = 
    {1,2,2,"a",null, null, 2,"a",3,2,null, "a"} 
in 
    List.Count( List.RemoveNulls( alist ))

 





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

Proud to be a Super User!





Parchitect
Impactful Individual
Impactful Individual

Hi @Dicken,

For pure null values, I would keep your first approach. It is probably the cleanest and easiest to read:

let
    alist = {1,2,2,"a",null, null, 2,"a",3,2,null, "a"}
in
    List.Count(alist) - List.NonNullCount(alist)

 

List.NonNullCount is built to count non-null items, so total count minus non-null count gives the null count.

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.