Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Counting True in a column of Bool (again)

NAC
6 - Meteoroid

My input is a table of 30 columns of bools.

I want to get 30 numbers counting how many trues there are in those 30 columns.

In Python with Numpy this is super easy, in SQL too.

However, with Alteryx I do not understand how to do so in an elegant way.

In the summarize tool there is a count Non Null but there is no count Non Zero (or Count True), how is this possible?

I am new to Alteryx and it's hard for me to get over such a missing essential feature.

 

Then I tried the solutions in this page:

 

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Counting-True-and-False-in-a-column-of...

 

However, I'm not sure if that solves my problem.

 

A first solution, not very elegant IMO, is casting every 30 columns to Bytes through the Formula tool. However, it takes forever to do so because it is not possible to copy paste a formula inside the formula tool (another thing I cannot get my head around).

 

Another solution is to use the summarize tool via the group by then sum method, but I could not get it to work since in the screenshot of that page the bool column is already a byte but mine is a bool.

 

Then there is the other solution with the frequency table and I did not try it because at this point I do not want the frequencies I want only to count the number of True values.

 

As an example, here is a little test table of 2 columns and 5 rows:

col1  col2

True True

True False

False True

False False

True False

 

col1 has 3 True and col2 has 2 True, that what I want to get.

6 REPLIES 6
RobertOdera
13 - Pulsar

Hi, @NAC 

Can you provide a sample file?

Happy to help if you can.

Cheers.

NAC
6 - Meteoroid

Here is a little test table of 2 columns and 5 rows:

col1  col2

True True

True False

False True

False False

True False

 

col1 has 3 True and col2 has 2 True, that what I want to get.

 

-------

 

I copy pasted this in the OP. I do not know how to delete this message, sorry.

RobertOdera
13 - Pulsar

Sure thing, @NAC 

 

Try this.

I used Multi-field Tool so that you can apply to multiple Columns at once.

Please mark as an acceptable solution + like, if it works for you.

 

RobertOdera_0-1593566928745.png

The workflow is attached.

Cheers!

 

NAC
6 - Meteoroid

Meanwhile, I found another slightly easier way to cast bools to Byte: the Select tool.

 

Capture d’écran (2).png

RobertOdera
13 - Pulsar

You're most welcome @NAC !

Cheers.

RobertOdera
13 - Pulsar

Yes! @NAC 

 

The Select Tool is an excellent go-to option if you don't have too many columns and if your flow will not be dynamically introducing new columns (that also need to be cast as Bool).

 

I love and resonate with your easier way.

It's "Good-enough," and you don't need to be detracted by the search for "Perfect."

 

Cheers!

 

 

Labels