Counting True in a column of Bool (again)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
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.
Solved! Go to Solution.
- Labels:
- Tips and Tricks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
The workflow is attached.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Meanwhile, I found another slightly easier way to cast bools to Byte: the Select tool.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You're most welcome @NAC !
Cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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!
