Excel > Exclude a named range from COUNTIFS - excel

I've got a spreadsheet with hundred of rows, each with a unique ID and each designated to a person.
On a different tab is a summary sheet where my formula goes (count of IDs for each person). On a third sheet, I have a named range 'excludes' which has certain IDs included in a single column.
i.e my sheet1 has:
ID Name
1 Bob
2 Bob
3 Bob
4 Shirley
5 Ted
6 Michael
The named range has say IDs, 2 and 3 in it, so I want my COUNTIFS to return the value 1 for Bob.
ID
2
3
Here's my formula but I think I'm missing something:
=COUNTIFS('Sheet1'!A:A,'summary'!$A1,'Sheet1!A:A,"<>excludes")
I want to exclude every ID in the excludes named range from my COUNTIFS result.
Do I need to use sumproduct or something?
Thanks for your help!

Use SUMPRODUCT:
=SUMPRODUCT((B2:B7=D2)*(ISERROR(MATCH(A2:A7,excludes,0))))
If you want countifs then you will need to count the whole and subtract where it exists in the named range:
=COUNTIFS(B:B,D2)-SUMPRODUCT(COUNTIFS(B:B,D2,A:A,excludes))

Related

Assigning a Unique ID to each Unique Name in Excel

I have a list of 20+ names in column A. There are some duplicates names in this list.
What I would like to do is assign a number to each of the unique name in the list. If a duplicate name occurs, the number should be duplicated as well.
Here's an example of what I am hoping to do:
Name ID
Alex 1
Allen 2
Bret 3
Dan 4
Dave 5
Dave 5
Harry 6
Joe 7
Joe 7
Tom 8
As you can see, a unique number is assigned to each of the name. Where a duplicate name appears, the original number gets duplicated as well, such as in the case of Dave and Joe.
If possible, I would like to avoid using VBA.
This list is dynamic and changes frequently, so I can't hardcode these numbers to each of the names, which is why I am hoping to get some assistance in developing a formula.
Try this in B2 and fill down.
=IFERROR(VLOOKUP(A2, A$1:B1, 2, FALSE), SUMPRODUCT(1/COUNTIF(A$2:A2, A$2:A2)))
Assuming this data starts with a header in A1:
In B2 put a 1 for your first unique id, then in B3 place the formula:
=IFERROR(VLOOKUP(A3, $A$2:$B2, 2, FALSE), B2+1)
And copy that down

Vlookup and sum all instances of the matching lookup

this is probably an extremely basic problem but I can't figure a way to do this within Excel.
I have a list of values IDs from a regional sales manager,
he wants to see if his figures have been inputted into the monthly report and are reporting correctly.
However, as he sells by region and we report by product we have multiple instances of his ID by Product
so our monthly report.. for example
ID Value
1 16,999
1 22,521
3 400
3 221
5 71
6 22,000
So he has provided me with a list of IDs
1
2
3
4
5
6
and wants a list with its total revenue not just the first match up.
Is an excel limitation or is there a way to do this?
You can use a SUMIF formula. Basically you give it the column to check the value of, then you give it the expected value and finally the colum to sum.
Option 1 (whole range)
=SUMIF(A:A, 1, B:B)
Option 2 (defined range)
=SUMIF(A1:A7, 1, B1:B7)
Option 3 (Using excel table)
=SUMIF([Id], 1, [Value])
For more details please refer to: https://support.office.com/en-ie/article/sumif-function-169b8c99-c05c-4483-a712-1697a653039b
Is this what you're looking for?
=SUMPRODUCT((A1:A5=1)*B1:B5)
Taken from here: Sum values from multiple rows using vlookup or index/match functions
How it works:
An array formula is used to create an array of numbers that gets passed to the SUMPRODUCT formula.
The array formula processes A1 and B1 together, then A2 and B2 and so on... if A1 is equal to 1, B1 is added to the array.

Formula to dynamically create column of values, excluding some by criteria

Say I have a column with these values on Sheet1:
IDs
1
2
3
4
5
6
Then a column with these values on Sheet2:
Used IDs
2
3
6
Is there a clever way I can write a formula on Sheet3 that shows only the IDs that are visible on Sheet1 but NOT on sheet2? Like this:
Unused IDs
1
4
5
I need something that would update dynamically as move values are added to the
Used IDs' column on Sheet2. I can make something work that simply omits the used IDs (retaining their rows as NULL), like this:
Unused IDs
1
4
5
However, I need something without the blank rows.
put this in A1 in Sheet3 and copy down till blanks:
=IFERROR(INDEX(Sheet1!A:A,AGGREGATE(15,6,ROW(Sheet1!$A$1:$A$6)/(NOT(ISNUMBER(MATCH(Sheet1!$A$1:$A$6,Sheet2!A:A,0)))),ROW(1:1))),"")

How can I remove non-matching values in two different columns and sort in Excel?

I have several columns of data in my Excel spreadsheet.
Originally, I had two different spreadsheets, as they were generated from reports in a software application.
One of the spreadsheets contains the names of individuals who have had transactions with us in the past year. The other spreadsheet contains the names and the phone numbers. I copied and pasted the columns with the names and phone numbers into my spreadsheet with just the names of people who have purchased something from us in the past year.
My ultimate goal is to extract the names and phone numbers of only the names that have purchased something in the past year.
My column for the past year contains 1,002 names, while my master customer list (with phone numbers) contains over 20,000 individuals. I need the phone numbers of all of the individuals that have purchased something from us in the past year, but I don't want to have to manually go through 1,000 names (and, essentially, 20,000+ to find the match).
If I can achieve my goal without having to use VBA, that would be great. If this is the only route I can take, then I will go that route, but I would like to avoid coding if possible. (This is simply due to time constraints.)
The VLOOKUP function is likely the best solution for you. From the Excel documentation, it:
Looks for a value in the leftmost column of a table, and then returns
a value in the same row from a column you specify. By default, the
table must be sorted in an ascending order.
Note well the implication of that last sentence: the column you're searching in (leftmost column of the lookup table) must be sorted in ascending order for this function to produce the correct results.
Taking a simple example, let's say you have Sheet1 in your Excel workbook with the following information:
A B C
1 Name Transactions Phone
2 Sally 3
3 Alice 5
4 Joe 2
5 Jon 1
You need to add their phone numbers to this sheet, from another workbook. Let's say your phone number information in the other workbook looks like this:
A B
1 Name Phone
2 Alice 2222222
3 Bill 3333333
4 Bob 4444444
5 Jim 5555555
6 Joe 6666666
7 Sally 7777777
8 Sue 8888888
9 Tom 9999999
Take the following steps to add the phone numbers to Sheet1 in the first workbook:
Copy the phone information into a blank sheet in the first workbook. Let's call this Sheet2 for this example.
Make sure the phone information is sorted ascending by the Name column (A), because that's the leftmost column and thus the lookup column.
In cell C2 of Sheet1 (the empty phone cell for Sally), enter: =VLOOKUP(A2, Sheet2!A$2:B$9, 2,FALSE).
Drag-copy this formula down to the remaining cells in the Phone column.
Result:
A B C
1 Name Transactions Phone
2 Sally 3 7777777
3 Alice 5 2222222
4 Joe 2 6666666
5 Jon 1 #N/A
Notes:
The second parameter (Table_array - the lookup data range) should not include the column headings. As you can see, it's Sheet2!A$2:B$9 so it includes the information from rows 2 to 9 in columns A and B.
The last parameter (Range_lookup) should be set to FALSE so you don't pick up the information from the closest match. Note how Jon has no matching phone number record, so his Phone is set to "#N/A" - otherwise he would have been assigned Joe's phone number since that's closest match to Jon.
Parameter documentation:
Lookup_value is the value to be found in the first column of the table, and can be a value, a reference, or a text string.
Table_array is a table of text, numbers, or logical values, in which data is retrieved. Table_array can be a reference to a range or
a range name.
Col_index_num is the column number in Table_array from which the matching value should be returned. The first column of values in
the table is column 1.
Range_lookup is a logical value: to find the closest match in the first column (sorted in ascending order) = TRUE or omitted; find
an exact match = FALSE.

COUNTIFS with range criteria on different sheets

I have not read if there is a limitation with COUNTIFS function, but I am experiencing the following:
I want to count the number the number of times two conditions are true in a row. For example
Sheet 1
USERID DATE
SAM 12/1/2014
SAM 12/3/2014
SAM 12/4/2014
JON 12/3/2014
BOB 11/5/2014
Sheet 2
Dates to match against {12/3/2014, 12/4/2014, 12/5/2014}
Sheet 3
USERID DATECount
SAM 2
JON 1
BOB 0
If all this information is in the same sheet the following formula works (Assuming data in Sheet 1 is in columns A and B, and the data in Sheet 2 is in the first row D to F, and the data in Sheet 3 starts at D5.
=COUNTIFS(A:A,D5,B:B,"="&$D$1:$F$1)
Currently, to get over this, I have a SUM function and a COUNTIFS for each criteria in the range for criteria 2. But it's pretty ugly since there are 20 criteria.
What I trying to find is a more elegant way to do this, or if there is another function that can return the same results.
Note that the date range can change every month.
You need a SUMPRODUCT wrapper that will iterate the COUNTIFS results through the cells in Sheet2!$D$1:$F$1.
      
The formula in Sheet3!E5 is,
=SUMPRODUCT(COUNTIFS(Sheet1!A:A,D5,Sheet1!B:B,Sheet2!$D$1:$F$1))
Fill down as necessary.

Resources