Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
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 ?
Solved! Go to Solution.
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.
List.Accumulate(alist, 0, (i,x) => i + Number.From(x=null))
List.Sum(List.Transform( alist, each Number.From(_=null)))
You don't need List.Accumulate, just List.Transform
List.Transform( alist , each Number.From(_ = null))
I know, I just liked it.
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 ) } )
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
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)
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 ))
Proud to be a 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.
This should work too...
let
alist =
{1,2,2,"a",null, null, 2,"a",3,2,null, "a"}
in
List.Count( List.RemoveNulls( alist ))
Proud to be a Super User! | |
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.
| User | Count |
|---|---|
| 12 | |
| 8 | |
| 5 | |
| 5 | |
| 5 |