Formula Help using COUNTIF on a table with OR logic

aprashar

New Member
Joined
Sep 9, 2016
Messages
2
I have a sample table listing some contacts with email addresses.

While there are many email addresses, using the HAVEEMGEMAIL column identifies "emgscc.com" users for me.

Regardless of the email address I have two columns, REASONA and REASONB, that flag accounts that I should not delete due to their TYPE.

I want to COUNTIF the rows where:
1. HAVEEMGEMAIL = TRUE
AND
2. REASONA *OR* REASONB contains "DON'T DELETE"

I have linked the and excel file and also have provided a picture, based on your need, for review. My apologies if these links do not work as it is the first time I am sharing any type of file with the Internet:
https://1drv.ms/f/s!AveqQKlPsI3k0lH7q_RlnT0olto3
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
For others to read the layout:


Excel 2010
ABCDEFG
1NAMEEMAILORGANIZATIONTYPEREASONAREASONBHAVEEMGEMAIL
2aa@aol.comSACRAMENTO COMMUNITY HOSPITALSTAFFFALSE
3bb@compuserve.comKAISERSTAFFFALSE
4cc@pacbell.netFITNESS THERAPYSTAFFFALSE
5dd@commodore.comGETWELLSTAFFFALSE
6ee@tandycorp.comSTANFORD HEALTH CARESTAFFFALSE
7ff@compaq.comKAISERMDDON'T DELETEFALSE
8gg@emgscc.comSACRAMENTO COMMUNITY HOSPITALSTAFFTRUE
9hh@aol.comKAISERSTAFFFALSE
10ii@emgscc.comKAISERSTAFFTRUE
11jj@compuserve.comGETWELLSTAFFFALSE
12kk@emgscc.comGETWELLPHYSICIANDON'T DELETEDON'T DELETETRUE
13ll@emgscc.comSACRAMENTO COMMUNITY HOSPITALSTAFFTRUE
14mm@aol.comGETWELLSTAFFFALSE
15nn@emgscc.comGETWELLSTAFFDON'T DELETETRUE
16oo@compuserve.comSACRAMENTO COMMUNITY HOSPITALMDDON'T DELETEDON'T DELETEFALSE
17pp@aol.comGETWELLSTAFFFALSE
18qq@emgscc.comSTANFORD HEALTH CAREPHYSICIANDON'T DELETEDON'T DELETETRUE
19rr@emgscc.comGETWELLSTAFFTRUE
20ss@emgscc.comKAISERSTAFFTRUE
21tt@compuserve.comGETWELLSTAFFDON'T DELETEFALSE
22uu@aol.comFITNESS THERAPYSTAFFDON'T DELETEFALSE
23vv@emgscc.comSACRAMENTO COMMUNITY HOSPITALSTAFFDON'T DELETETRUE
24ww@emgscc.comSACRAMENTO COMMUNITY HOSPITALSTAFFDON'T DELETETRUE
25xx@aol.comSACRAMENTO COMMUNITY HOSPITALSTAFFDON'T DELETEFALSE
26yy@compuserve.comKAISERSTAFFDON'T DELETEFALSE
27zz@emgscc.comSACRAMENTO COMMUNITY HOSPITALSTAFFDON'T DELETETRUE
Sheet1
 
Upvote 0
Welcome to the Board!

I imagine that there has to be a better way than this, but it works (based on the data 63falcondude posted):
Code:
=COUNTIFS(G2:G27,"TRUE",E2:E27,"DON'T DELETE")
 +COUNTIFS(G2:G27,"TRUE",F2:F27,"DON'T DELETE")
 -COUNTIFS(G2:G27,"TRUE",E2:E27,"DON'T DELETE",F2:F27,"DON'T DELETE")
 
Last edited:
Upvote 0
If you create a helper column H with the formula =OR(E2="DON'T DELETE",F2="DON'T DELETE"), then you can use the formula =COUNTIFS(G2:G27,TRUE,H2:H27,TRUE)
 
Upvote 0
"Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Thanks to Joe4 and 63falcondude. I am going to spend the next few minutes understanding their solutions backwards and forwards. I wish I came to you guys 7 hours ago.
 
Upvote 0
You are welcome!

To learn more about COUNTIFS, see: https://www.techonthenet.com/excel/formulas/countifs.php

The issue is that criteria in COUNTIFS is treated as an AND condition, and you have an OR condition in your request.
So, the logic in my solution was to do it this way:
1. COUNT the number of records that have TRUE in Column G, and "DON'T DELETE" in column E
and then add it to the following:
2. COUNT the number of records that have TRUE in Column G, and "DON'T DELETE" in column F
however, there are people "DON'T DELETE" in columns E and F, so they are being double-counted, so we must subtract the following:
3. COUNT the number of records that have TRUE in Column G, and "DON'T DELETE" in column E, and and "DON'T DELETE" in column F

Hope that makes sense!
 
Upvote 0

Forum statistics

Threads
1,215,917
Messages
6,127,703
Members
449,399
Latest member
VEVE4014

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top