Count of boolean field

Hello! I have a boolean field I need to be able to count "true" instances so that I can create a custom column or field that compares the count of that boolean to another (non-boolean) column's total. I've tried reading up in the documentation and anything I've tried returns an error.

Hi @Sarah_McRae
I'm not sure I understand what you are doing, so a screenshot and the expressions would be helpful. As well as "Diagnostic Info" from Admin > Troubleshooting.
Perhaps you are trying to do this, which has a workaround, see comments:
https://github.com/metabase/metabase/issues/15922 - upvote by clicking :+1: on the first post

Thanks @flamber, I'll add some screenshots and the exact error message.


Custom Field 1
Please see the screenshots attached. I am trying to divide the number of instances of true "has_connected" by the number of instances of "profile_is_completed".

This is the first way that I tried. I also tried "countif" with another error.

@Sarah_McRae I don't understand your data, but you have casting problems.
You should create a custom expression metric (not a custom column) like:
CountIf([has_connected] = true) / CountIf([profile_is_completed] = true)

1 Like

Thank you, I was able to solve the issue using your response.

@flamber I tried the same idea again, with a subtraction instead, and it gives me another error.

What I tried to use: CountIf([has_sent_a_message] = True) - CountIf([has_received_a_response_to_first_message] = True)

What I receive: ERROR: column "source.profile_is_completed" must appear in the GROUP BY clause or be used in an aggregate function Position: 462

@Sarah_McRae Post the full error details from Admin > Troubleshooting > Logs.