Excel: Get values in non-adjacent cells based on multiple criteria - excel

I have an excel sheet sort of like this:
I'm trying to figure out how to get the totals in cells B1 through B4.
I tried INDEX-MATCH, where I tried to match the words in A1:A4 with the words in row 7, get the numbers relative to them, and then sum them, but it was a lot of Google searching and stabbing in the dark -- every attempt returned an error.
I also tried to INDEX-MATCH the words in A1:A4 with row 7, and then nest a VLOOKUP in there where it'd get the number relative to "visits:" but that didn't work at all either.
Is INDEX-MATCH even the correct function? Any help would be much appreciated, I'm not even sure what to Google anymore.
EDIT: I need to use a search function of some kind, like the INDEX-MATCH method, rather that static formulas because the sheet will change periodically and I don't want to have to update the formula every time I add an animal.

Your data table is unusual in structure.
However, if you are gong to keep a fixed rule such that the number of visits is always offset 2 rows and 1 column from the animal type(and that itself is always in row 7), you could do:
In B1:
=SUM(IF($A$7:$AAA$7=$A1, $B$9:$AAB$9, 0))
Confirm with Ctrl-Shift-Enter, and then copy down..

DOes this work?
=SUM(IF($B$7=A1,$C$9,0),IF($D$7=A1,$E$9,0),IF($F$7=A1,$G$9,0),IF($H$7=A1,$I$9,0))

I'm not sureto have fully grasped your challenge. Yet it seems the following solution would work:
Add the following formula in each box where the number of visits is added as
=+SUMIF($A$1:$A$end;animal;$B$1:$B$end)
Where end is a number of the last cell in the first and second columns data contain the data.
And animal is the cell that contains the name of the animal.
Therefore in your simple example, the formulas on cells C9;E9;G9 and I9 would be respectively:
=+SUMIF($A$1:$A$4;B7;$B$1:$B$4) ; =+SUMIF($A$1:$A$4;D7;$B$1:$B$4); =+SUMIF($A$1:$A$4;F7;$B$1:$B$4) and =+SUMIF($A$1:$A$4;H7;$B$1:$B$4).

Related

Returning data from across multiple worksheets in Excel

How do you create formulas that will return the totals, averages, counts, min, max, etc from different worksheets? The columns (that exist) are consistent in their header information, but may or may not be different from one sheet to the next, column number wise. Let's say I have 7 tabs of data, some or all of them may contain a column heading of beans, for example, but the column numbers may or may not be consistent across all tabs, where present. Their actual locations within the worksheet are completely dynamic.
My spreadsheet has several tabs of raw data that I want to compare against in a summary/report sheet. I'm sure this can be done but I am afraid it is a little too far beyond the capability of this old brain.
I've thought about and toyed with a bunch of formulas using indirect, index, match and just can't figure it out. Your help would be most appreciated. Thanks
Here's a possible function only solution. The final result will look like:
We will use four(4) primary functions:
ADDRESS
INDIRECT
MATCH
LEFT
Note: Just follow the link if you have question on how to use these functions
The formula: This is in cell C4 Above
=AVERAGE(
INDIRECT(
"'"& C$3 & "'!" &
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
& ":" &
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
)
)
Edit1: To handle the comment below for headers beyond 26, change this
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
to this:
SUBSTITUTE(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),"1","")
Basically what is does is:
Find where the header Bean is located using MATCH function. To do that, you will have to incorporate the use of INDIRECT since your sheet name is dynamic (in this example, your sheet name is in C3 - Data1). (I assumed all your headers are in 1st row, I use 1:1 in there). Note: In this example, Bean is in column H of Data1 sheet
MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0) <~~ returns 8
After finding where it is, we need to get the entire column address so we can apply counting and summing functions (e.g. SUM,COUNT,AVERAGE etc...). To do that we use the ADDRESS function combined with LEFT to get the column letter.
LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1) <~~ returns H
Then we just repeat that formula and connect it with : to get H:H
Now that we have the column address, we simply connect it again with the sheet name and apply the final INDIRECT function plus the counting and/or summing function of your choice.
Sample formula of Total in C5:
Sample formula of Max in C6:
Finally, all you have to do is copy the formula across all columns with sheet name. Just add sheet names beside the last one and copy formula. That's it. I hope this is close to what you want and I hope that all the functions I used are available in Excel 2000.

How to tell if a cell exists on another Google Sheet

I have 12 sheets in one Google Sheets document labeled for each month (January - December). On each sheet column A contains a project number, e.g. "6091".
I'm trying to find a function that will check all of the other sheets to see if there are duplicate cells in the "project number" column of other sheets.
So: "Do any of the cells in column A, match any of the cells in column A on other sheets".
Is there a quick way to do this?
The formula =arrayformula(iferror(match(A2:A, AnotherSheet!A2:A, 0))) checks each value in A2:A of the present sheet for being in A2:A of AnotherSheet. If it's there, it returns the position in AnotherSheet, otherwise the output is empty (the error #N/A is suppressed by iferror).
You can use the above for each of the sheets separately. Alternatively, if you are not interested in the positions and just want to know which entries from A2:A are found elsewhere, then add the results for each sheet:
=arrayformula(iferror(match(A2:A, AnotherSheet!A2:A, 0)) + iferror(match(A2:A, ThirdSheet!A2:A, 0)))
The output is 0 is there is no match, and a nonzero number if there is.
You may try using this to find the number of duplicates:
=counta('JAN'!A:A,'FEB'!A:A)-countA(unique({'JAN'!A:A;'FEB'!A:A})
Where A:A is your column for the data you want to check and the respective files.
This formula counts the total number of data you have, minus the unique data, therefore giving you the total number of duplicates in your dataset.
This formula gives you an overview of the total number of duplicates, however, it doesn't show which cell is a duplicate.
Alternatively, you can add a checker column and input the following formula to check if that specific cell is a duplicate.
=match(cell to check,{range 1;range 2;...range 12})
Alternatively, you may use this formula to find the exact duplicates between the ranges, however this formula does not search within the range itself for duplicates.
=arrayformula(filter(range to check,(countif(arrayformula({Range 1;range 2}),{range to check}))>1))
Personally I think that the last option would be the best as it gives you the exact data to correct.
I am still new to this so hope this helps:)
This formula should work for numerical values:
=COUNT(QUERY({March!A:A;April!A:A},"where Col1="&A2))
If you are searching for text values it would be
=COUNTA(QUERY({March!A:A;April!A:A},"where Col1='"&A2&"'"))
Unfortunately the QUERY function does not work within an arrayformula so you would need to copy the formula down the column. You can add in extra sheets into the { } array as required, separated by a semi-colon
Edit: actually, borrowing from #sandwich, this version should work without the need to copy the formula down the column:
=arrayformula(iferror(match(A2:A,{March!A:A;April!A:A},0)))

Sumproduct or Countif on a 2D matrix

I'm working on data from a population of people with allergies. Each person has a unique ExceptionID, and each allergen has a unique AllergenID (451 in total).
I have a data table with 2 columns (ExceptionID and AllergenID), where each person's allergies are listed row by row. This means that the ExceptionID column has repeated values for people with multiple allergies, and the AllergenID column has repeated values for the different people who have that allergy.
I am trying to count how many times each pair of allergies is present in this population (e.g. Allergen#107 & Allergen#108, Allergen#107 & Allergen#109,etc). To keep it simple I've created a matrix of 451 rows X 451 columns, representing every pair (twice actually because A/B and B/A are equivalent).
I somehow need to use the row name (allergenID) to lookup the ExceptionID in my data table, and count the cases where that matches the ExceptionIDs from the column name (also AllergenID). I have no problem using Vlookup or Index/Match, but I'm struggling with the correct combination of a lookup and Sumproduct or Countif formula.
Any help is greatly appreciated!
Mike
PS I'm using Excel 2016 if that changes anything.
-=UPDATE=-
So the methods suggested by Dirk and MacroMarc both worked, though I couldn't apply the latter to my full data set (17,000+ rows) because it was taking a long time.
I've since decided to turn this into a VBA macro because we now want to see the counts of triplets instead of pairs.
With the 2 columns you start with, it is as good as impossible... You would need to check every ExceptionID to have 2 different specific AllergenID. Better use a helper-table with ExceptionID as rows and AllergenID as columns (or the opposite... whatever you like). The helper table needs a formula like:
=COUNTIFS($A:$A,$D2,$B:$B,E$1)
Which then can be auto-filled. (The ranges are from my example, you need to change them to your needs).
With this helper-matrix you can easily go for your bigger matrix like this:
=COUNTIFS(E:E,1,INDEX($E:$G,,MATCH($I2,$E$1:$G$1,0)),1)
Again, you can auto-fill with this formula, but you need to change it, so it fits your needs.
Because the columns have the same ID2 (would be your AllergenID), there is no need to lookup them because E:E changes automatically with the auto-fill.
Most important part of the formulas are the $ which should not be messed up, or you can not auto-fill it.
Picture of my self-made example (formulas are from the upper left cell in each table):
If you still have any questions, just ask :)
It can be done straight from your original set-up with array formulas:
Please note that array formulas MUST be entered with Ctrl-Shift-Enter, before copying across and down:
In the example pic, I have NAMED the data ranges $A$2:$A$21 as 'People' and $B$2:$B$21 as 'Allergens' to make it a nicer set-up. You can see in the formula bar how that looks as a formula. However you could use the standard references like this in your first matrix cell:
EDIT: silly me, N function is not needed to turn the booleans into 1's and 0's, since multiplying booleans will do the trick. Below formula works...
SUM(IF(MATCH($A$2:$A$21,$A$2:$A$21,0)=ROW($A$2:$A$21)-1, NOT(ISERROR(MATCH($A$2:$A$21&$E2,$A$2:$A$21&$B$2:$B$21,0)))*NOT(ISERROR(MATCH($A$2:$A$21&F$1, $A$2:$A$21&$B$2:$B$21,0))), 0))
Then copy from F2 across and down. It can be perhaps improved in technique with sumproduct or whatever, but it's just a rough example of the technique....

Make COUNTIFS ignore blank cells

I am trying to use a COUNTIFS formula to calculate how many installs are done. This is done by searching through a large table containing many blank cells. When using the following formula, I receive a #VALUE! error because Excel sees the blank cells as 0s and gets confused trying to count strings and integers:
=COUNTIFS(B10:B152,"Installs",D10:N152,"Done")
The range D10:N152 contains blanks and is causing the error.
Can I make Excel ignore those blanks or see them as strings instead of integers?
For COUNTIFS:
Important Each additional range must have the same number of rows and columns as the criteria_range1 argument. The ranges do not have to be adjacent to each other.
Maybe add a helper column, say O with:
=IF(MATCH("Done",D10:N10,0)>=1,"Done","")
copied down to suit and then:
=COUNTIFS(B10:B152,"Installs",O10:O152,"Done")
Now we know only one Done per row (and assuming Done is on its own in a cell) then a helper column with say:
=COUNTIF(D10:N10,"Done")
would be a shorter formula than =IF(MATCH("Done",D10:N10,0)>=1,"Done","") and also allow a shorter formula than =COUNTIFS(B10:B152,"Installs",O10:O152,"Done") for the counting, say:
=SUM(O:O)
instead (assuming the rest of ColumnO is blank or text, otherwise =SUM(O10:O152).
However I aimed for a formula as similar as possible to that used by OP, for which the helper column needed to be populated with Done also. At the time I was allowing for the possibility there might be more than one Done per row.
As pointed out in a comment, the helper column might have been populated with fewer keystrokes than =IF(MATCH("Done",D10:N10,0)>=1,"Done",""), if only by excluding the result for failure of the test, say =IF(MATCH("Done",D10:N10,0)>=1,"Done") since MATCH never ‘fails’ – rather it returns #N/A where no match is found, which is good enough for a COUNTIF function since that does not count #N/As when the criterion is Done.
Try this FormulaArray:
=SUM(($B$10:$B$152="Installs")*($D$10:$N$152="Done"))

Using the 'Match' function in Excel to return a cell address

I have a list of numbers in a table that I would like to search for and bring back the cell reference of where that number resides. For example the data looks like:
A B C D
1 1 2 3 4
ok it doesn't come out very well as the first one is the row number and then each number below sits under each letter, so C1 would contain '3'....
If I wanted to return the reference number of C1 in a cell I am using the formula of =CELL("address",MATCH(AU14,C1:AG1)) but this just errors. I have tried to put an Index in there too, but I believe that index only works vertically so this bring back a #N/A result.
Can anyone assist as I've wasted too much time on this already! :)
You are indeed missing an INDEX. And INDEX works vertically, horizontally, or both depending on how it's called.
Here is a formula that works for the ranges in the pictures. Should be easy to modify.
Formula in C5
=CELL("address",INDEX(B2:F2,MATCH(C4,B2:F2,0)))
formula
results
To make CELL work you need a cell reference, e.g.
CELL("address",C1)
The trouble is that MATCH just gives you a number, not a cell reference.
Probably the easiest way is to use the ADDRESS function, so a first try might be
=ADDRESS(1,MATCH(AU14,C1:AG1,0)+2)
That would give you the right answer if AU14 contained 3, but isn't considered to be very good because it wouldn't update if you deleted/inserted rows or columns.
A better one would be
=ADDRESS(ROW(C1),MATCH(AU14,C1:AG1,0)+COLUMN(C1)-1)
Then you might want to put in some error handling for the case where it's not found
=IFERROR(ADDRESS(ROW(C1),MATCH(AU14,C1:AG1,0)+COLUMN(C1)-1),"Not found")

Resources