Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Count columns that are non-null, non-blank, non-zero

I have survey data I work with that typically has about 50 columns or more. In the past, in Excel, I would add a column with the formula countifs(rng1,"<>",rng1,"<>0") and call this "Answered" (abrev...
  • AlexisOlson's avatar
    4 years ago

    Personally, I would try the unpivot route first and try other methods if that didn't work efficiently.

     

    If you go with a custom column, I'd do this to avoid the extra replacement step:

    List.Count(List.Difference(List.Range(Record.FieldValues(_),3), {null, "", 0}))
  • Anonymous's avatar
    Anonymous
    4 years ago

    My apologies, took me a while to come back and fully test (we were short-staffed/recent turnover).  The solution you gave me was almost there. It wasn't counting correctly when it came across rows with nulls in all columns. But this is what I modified it to (added List.RemoveNulls).

    = Table.AddColumn(#"Changed Type", "NullBlankSpaceZero", each List.Count(List.RemoveNulls(List.Difference(List.Range(Record.FieldValues(_),2), {null, "", " ", 0}))))

     

    note: there are some small differences from what I initially gave as an example that's why I adjusted field values and list diff compare list.

     

    Thanks again! your reply set me on the right path