Excel: Find matching row with numerical range - excel

I have a spreadsheet with Company Name and Serial Number columns. The serial number column values are in range e.g. 1001-2000. How do I look up company name from a specific serial number value? See this screenshot for example.
Column B can be split into two columns if needed though it is preferable to have single column.
I tried this example but got a #Spill! error

Or, using Lookup+Imreal function
In E2, enter formula:
=LOOKUP(D2,IMREAL(B2:B5&"i"),A2:A5)

Be careful with this... It is a crude hack.
=IF(D2<=1000,A2,INDEX(A:A,MATCH(D2+1&"-"&D2,B:B,1)))

in the special case of the ranges all ending at a multiple of 1000 and each band being essentially 1000 units you could go with the special case formula of
=INDEX($A$2:$A$5,INT(($D2-1)/1000)+1)
Note that you don't actually use the info in column B for this option. It is based purely on the pattern to the range breakdown
if you want to restrict it to values between 1 and 4000 you could wrap it in an if statement that checks for that.
=IF(AND(D2>=1,D2<=4000),INDEX($A$2:$A$5,INT(($D2-1)/1000)+1),"SN out of range")

Related

SUMIFS Excel Multi Criteria

I'm trying to do use SUMIFS to calculate the total QTY changes for drawings with a material ID that Matches the Pipe Indent Numbers and ignore the ones that are NOT listed the piping indent numbers column. Below is what I have so far but I know the "=D:D" looks wrong.
I don't know how to reference all the numbers in the Pipe Indent Numbers List(D:) as each their own criteria, so that if the Material ID matches ANY of the Pipe Ident Numbers it will sum it.
I need help with this because my actual Pipe Ident Numbers column have about 100 other numbers not just the 5 shown.
Also not sure would I need to have the drawing number in the formula somewhere too? Maybe that's what I'm missing...
=SUMIFS(C:C,B:B,"=D:D")
Any help would be amazing! Thanks :)
you can use
if you want to compare row by row
=SUMPRODUCT(c2:c6*(b2:b6=d2:d6))
if you want to compare the value in column b with all values in column d (of you do not use Excel 365 press CTRL+SHIFT+ENTER to enter the formular)
=SUMPRODUCT(c2:c6*(b2:b6=TRANSPOSE(d2:d6)))
Best Regards
Chris
Use:
=SUMPRODUCT(SUMIFS(C:C,B:B,D2:D6))
One can use D:D but that would do many unneeded calculations. One should limit the range to the dataset.

Excel counting combinations of logical statements

I have a spreadsheet with data in multiple catagories, e.g. Pet (Dog, Cat, Rabbit), gender (M,F), mode of transport(Car,Bike,Skateboard). For each individual, these can either be true or false. I want to count the number of individuals with a particular combination of pet, gender, mode of transport. I want this to be automatic, so I can specify the gender, pet, mode of transport in cells and the formula counts based on these values.
e.g. How many people are Male, have a Dog and have a Bike? In this case, Male, Dog and Bike need to be read from cells in the spreadsheet.
I have a formula which uses indirect and offset to select columns but can't help but think there must be a better way.
Here's an example which makes it far clearer than my wordy explanation above. Thanks in advance for your help.
Is there a way of representing my data that's better suited to make this counting easier?
Google Drive Link to Excel file
A very valid - I don't download random files from the internet comment:
Here's a csv:
Name,Dog,Cat,Rabbit,Male,Female,Car,Bike,Skateboard
Alice,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,TRUE,FALSE
Bob,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,TRUE,FALSE
Chris,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE
Dave,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,TRUE
Ellie,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE
Frank,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE
Gerald,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE
Also the formula I used was:
=COUNTIFS( OFFSET(INDIRECT("R3C"&MATCH(L3,Headings,0),FALSE),0,0,numberOfPeople,1),TRUE,
OFFSET(INDIRECT("R3C"&MATCH(M3,Headings,0),FALSE),0,0,numberOfPeople,1),TRUE,
OFFSET(INDIRECT("R3C"&MATCH(N3,Headings,0),FALSE),0,0,numberOfPeople,1),TRUE)
Where numberOfPeople is a reference to a cell that counted the number of entries. And headings is a reference to the column headings of the table.
OFFSET and INDIRECT are volatile functions, in that they will recalculate every time excel calculates regardless if the underlying data has changed or not.
I prefer to use INDEX to return a range.
INDEX takes 3 criteria. INDEX(range,row,column). By putting 0 in the row criterion it will return the full column.
so using MATCH to find the correct column and 0 for row we get the correct column returned.
=COUNTIFS(INDEX(A:I,0,MATCH($K$2,1:1,0)),TRUE,INDEX(A:I,0,MATCH($K$3,1:1,0)),TRUE,INDEX(A:I,0,MATCH($K$4,1:1,0)),TRUE)
It is pretty easy if you use the COUNTIFS formula combined with several IF statements. Here is what should work (put in "O3" and copy down):
=COUNTIFS(IF($L3=F$2,$F$3:$F$9,$G$3:$G$9),TRUE,IF($M3=C$2,$C$3:$C$9,IF($M3=D$2,$D$3:$D$9,$E$3:$E$9)),TRUE,IF($N3=H$2,$H$3:$H$9,IF($N3=I$2,$I$3:$I$9,$J$3:$J$9)),TRUE)
This compares the given values for your categories in the inner IF statements and returns the corresponding columns to check for TRUE. What COUNTIFS does then is to count all rows where the criteria is TRUE for all given criterias. You can also expand your categories by adding more inner IF statements to return corresponding rows.
It would not be quite easy to change your data representation due to the fact that you can have multiple values for one row. You would have to split data with multiple values into multiple rows. Here is an example:
You could then just use the following formula:
=COUNTIFS($D$3:$D$14,$L3,$C$3:$C$14,$M3,$E$3:$E$14,$N3)
Having given Gender in "L3", given Pet in "M3", given Transportation in "N3".
If you have further questions, leave a comment.

Excel - How to count unique days in a list a duplicated days

Having a list of days suchs as:
01-giu-16
01-giu-16
01-giu-16
31-mag-16
31-mag-16
31-mag-16
31-mag-16
30-mag-16
I was looking for an excel formula that helps me count the number of unique days in the list (in this example 3)
Moreover I need the count only for the dates which have a specific ID in the next column (for example 1565)
Without any additional criteria, you can achieve the uniqueness count by using
=SUMPRODUCT(1/COUNTIF(A1:A8,A1:A8)), assuming your data are in the range A1:A8.
To evaluate subject to additional criteria (suppose they are in column B), use
{=SUM(--(FREQUENCY(IF(B1:B8=1565,MATCH(A1:A8,A1:A8,0)),ROW(A1:A8)-ROW(A1)+1)>0))}
This is an array formula: use Ctrl + Shift + Return once you're done editing (and don't type the curly braces yourself). Personally though I think this exceeds the reasonable threshold for complexity: I'd be inclined to adopt the first approach on a column that represents an intermediate transformation of your input data.
Lets assume your data is in Column A and it has a header row. So the first data number will actually be in A2. Place this formula in B2 and copy down beside your list. It will generate a list of unique cell numbers from column A. Once you have the list you simply need to use a function to count the side of it.
=iferror(INDEX($A$2:$A$5,MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$5),0,0),0)),"")
in C2 you can use the following formula to get the number of unique cell numbers
=COUNTA(B2:B9)-COUNTIF(B2:B9,"")
In D2 you can use the following formula to get the count of each unique cell number from your original list. Copy it down as far as you need to go.
=IF(B5="","",COUNTIF($A$2:$A$9,B5))

Excel: Count cell once within a column when it meets at least one of multiple conditions

I'm working in Excel 2013. I've had a quick google for this, but I think my terminology might be wrong as I'm not finding a response that solves my exact problem.
I have a column of concatenated healthcare-related outcomes, such as:
"999 Emergency Ambulance By Co-op Admit Accident & Emergency! Admitted To Hospital"
"Advice Only"
"Admit to hospital"
"Medication prescribed"
I want to enter one formula in one cell that counts the records that EITHER contain "999" "Admit" OR "A&E" OR "Admission" for the ENTIRE column.
I don't want to have another column performing this count, I know the following works:
=IF(ISNUMBER(SEARCH("999",K2)),1,IF(ISNUMBER(SEARCH("ADMIT",K2)),1,IF(ISNUMBER(SEARCH("ADMISSION",K2)),1,0)))
But the formula I would need would replace the sum of the column that contained the above formula, negating the need for an extra column.
What I'm struggling with is that the other solutions I've seen would check the column for each condition and you'd end up with cells counted twice. As you can see in the above, some cells will contain "999" AND "Admit".
Apologies if this is a simple question!
Thanks in advance.
You can use this formula:
=SUMPRODUCT(1*((NOT(ISERROR(SEARCH("999";A1:A4)))+NOT(ISERROR(SEARCH("Admit";A1:A4)))+NOT(ISERROR(SEARCH("Admission";A1:A4))))>0))
Or, as in your example, use Isnumber instead of NOT(ISERROR(
Depending on your regional settings you may need to replace field separator ";" by ","
You can use MMULT here to avoid some repetition, i.e.
=SUMPRODUCT((MMULT(ISNUMBER(SEARCH({999,"Admit","A&E","Admission"},K2:K100))+0,{1;1;1;1})>0)+0)
Assumes data in the range K2:K100 - change as required
Note that there are 4 1s in {1;1;1;1} to match the 4 search terms - if you increase the number of search terms you need to increase the numbers of 1s

Returning a value if three columns match in excel

I have two excel sheets where I need to match three values to return a fourth. The similar columns are month, agent, and subdomain. The fourth column is called difference.
Concatenate would work, as per #MakeCents suggestion, but if you don't want a helper column, SUMPRODUCT would work.
example:
=SUMPRODUCT(--(A2:A12="d"),--(B2:B12="S"),--(C2:C12="Apr"),D2:D12)
would search range A2:A12 for "d", B2:B12 for "S" and C2:C12 for "Apr", and return the value fom D2:D12 that corresponds to where all 3 are true. If multiple lines match, it will add the value in D2:D12 for all matching rows.
The -- is used to change the True/False results into 0 and 1 for use in multiplication
Limitations of SUMPRODUCT
Recommended to specify the range explicitly; it will be slower with just
column references
(A1:A4000 is ok, A:A is not)
It will return an error if any of the values are errors
It will return numeric results only - text is evaluated as Zero
Although I believe #MakeCents comment / suggestion on how to do this is the way I would go since it is the simplest, you could accomplish this a different way (MUCH more processor-intensive, though) using the Index() and Match() functions and Array formulas.
For example, suppose your 3 columns of data you're looking to match against are columns A-C and you're looking to return the matching value from column D in Sheet1
Now, the 3 values you're looking to have matched are in cells A1, B1 & C1 of Sheet2, you could use the following formula:
=INDEX(Sheet1!D:D,MATCH(1,(Sheet1!A:A=A1)*(Sheet1!B:B=B1)*(Sheet1!C:C=C1),0))
And ENTER IT AS AN ARRAY FORMULA by pressing Ctrl + Shift + Enter
Hope this helps!
You are looking for a Lookup with multiple criteria.
One of the most robust options is
=INDEX(D:D,SUMPRODUCT(--(A:A="d"),--(B:B="S"),--(C:C="Apr"),ROW(D:D)),0)
It does not need to be entered as an array formula.
Taken from [1] (blogs.office.com).
See also this very complete answer, which summarizes this and other options for performing a lookup with multiple criteria.
PS1: Note that I used references to full columns, as per this.
PS2: This can be considered an enhancement to the solution by Sean for the case when the output column does not contain numbers.
References
[1] This post is written by JP Pinto, the winner of the Great White Shark Award given for the best article written about VLOOKUP during VLOOKUP Week.
Try this
=IF(A4=Data!$A$4:$A$741,IF(B4=Data!$B$4:$B$741,"Hai"))

Resources