Conditional VLOOKUP - excel

I have two excel spreadsheets:
One has an id and a date
The other one has an id, two dates and a value
I am supposed to match the ids and return the value whenever the date in spreadsheet 1 is between the two dates in spreadsheet 2.
There is a one-to-one correspondance between those spreadsheets, and a default value of 0 if no match is found
The first spreasheet has a lot of lines. Would there be some sort of VLOOKUP function that I can use to get the right data?

SUMPRODUCT and array formula's are what you need.
=SUMPRODUCT(--(Sheet2!$A$2:$A$2000=A2),--(Sheet2!$B$2:$B$2000<B2),--(Sheet2!$C$2:$C$2000>B2),--(Sheet2!$D$2:$D$2000))
this will have to be entered as an array formula with CTRL+SHIFT+Enter. you will see excel surrond the formula with {} if you have entered it correctly.
Assumptions: ID to be checked in A2, Date to be checked in B2
Data on sheet 2 in the order A ID, B start date, C end date, and D value (numeric)
the array formula returns a list of true/false, which is then multiplied together. only if all criteria are True is a value returned (as any False answers equate to zero, and zero * another number is zero).
This will give incorrect answers if 2 ranges overlap

There was a very simple way to achieve that: concatenate the multiple fields you want to search, and you are done, provided they are unique. Otherwise you should look into array cells.

Related

Return value in a specific column based on array formula result

I am using an array formula to find the largest value within a given month. Photo below ('Range of values') shows the values for each month, and I am selecting September as the criteria ("K5" in the formula below). Cell K5 will change based on the specific month I am looking for:
Formula:
{=MAX(IF(E8:P8=K5,E12:P21,""))}
Result:
63,490
Requirement:
I need to have a cell with the result, and a cell next to it with the corresponding 'Location', which in this case would be 6.
What would be the best formula to use in the case where you are not confined to a single column for the value lookup?
Typical Vlookup and Index/Match as I understand are limited as they require a single column to look up a value. The array is outside of that scope, but I feel I may be overthinking it, but I don't know.
if you have Excel 365 current channel you can use this formula to return both values:
=LET(data,A1:D5,
selectMonth,B7,
dataMonth,CHOOSECOLS(data,1,MATCH(selectMonth,CHOOSEROWS(data,1),0)),
TAKE(SORT(dataMonth,2,-1),2))
The basic idea is to first reduce the data range to the first column and the month that should be evaluated.
Then sort that "range" descending by the months values (= column 2 of new range) and take the first 2 rows (including header) - as this is the max value.

EXCEL Get the shift of the person based on date

I am looking for a formula where the shift of the person will show based on the given date.
So what I hope to achieve is the Persons schedule will show depending on the date.
Is it ok if you move the "Date" column to the left in both sheets? If yes, then you can use "VLOOKUP" function for the desired result. I think it'll be much easier. If you need any help regarding VLOOKUP function I'll help you.
Ashgabat.
If your data in Sheet1 is in cells A1:D10 and your data in Sheet2 is in columns A:E then use the following formula in B2 entered with ctrl+shift+enter:
=INDEX(Sheet2!C:C,MATCH(1,(#$A:$A=Sheet2!$A:$A)*(#$D:$D=Sheet2!$E:$E)*("shift"=Sheet2!$B:$B),0))
Drag down and to the right.
It looks for a match of 1 for 3 conditions (condition true = 1, false= 0). If at least one of the conditions is false it's multiplied by 0 and results in 0. If all conditions are true it's 111 = 1. That would be the match. It counts the position of that match in the array and returns that as a result, which equals the row number.
It indexes the column mentioned in the index formula and returns the value of the calculated row number.

IF Function/VLOOKUP Combo

So this seems like it should be pretty easy. I could just concatenate and make another column in the data to make a unique combo and get my answer. But that just seems so messy. So here I am reaching out to you fine folks to pick your brains.
I want to look up HQLine and Description in the MPCC tab to return the correct MPCC Code. I tried a couple IF statements with VLOOKUPS but couldn't get it right.
So I need to look up BK3 Positive Crankcase Ventilation (PCV) Connector in the MPCC tab. So it needs to match BK3 and the Long description and then give me the correct code.
Here is the missing data file
Here is the MPCC export list that I want to search
Use SUMIFS.
SUMIFS will find the sum in a table of rows that meet certain criteria. If the MPCC is always a number, and the MQAb-LongDescription is always unique, SUMIFS will find the correct ID.
=SUMIFS(Sheet1!C$2:C$100,Sheet1!A$2:A$100,A2,Sheet1!B$2:B$100,B2)
where Sheet1!A$2:A$100 is the HQAb data, Sheet1!B$2:B$100 is the Long Description data, Sheet1!C$2:C$100 is the MPCC Number data, A2 is the HQLine, and B2 is the Description.
The formula would go in C1.
More information on VLookup with Multiple Criteria
You can use an Index/Match with multiple criteria.
I'm assuming that you will put this formula in "Sheet1", cell C2, and your lookup data is in a sheet called "Sheet2", columns A, B, C from row 2 to 30.
Put this in Sheet1, C2:
=INDEX(Sheet2!$C$2:$C$30,MATCH(A2&B2,Sheet2!$A$2:$A$30&Sheet2!$B$2:$B$30,0))
(Enter with CTRL+SHIFT+ENTER) and drag down.)
Adjust the ranges as necessary.
lets assume your first Table is on sheet 1 in the range A1:C11 and the MPCC codes are located on Sheet 2 in the range A1:C32. Each table has a header row so your data really starts in row 2.
Similar to BruceWayne's answer of using an array formula, you can bring the array calculation inside of a formula and avoid the special array treatment. There are a few functions that can do this. I will demonstrate with the SUMPRODUCT function;
On Sheet 1, Cell C2, use the following formula:
=INDEX('Sheet 2'!$C$1:C$32,SUMPRODUCT((A2='Sheet 2'!$A$2:A$32)*(B2='Sheet 2'!$B$2:B$32)*row('Sheet 2'!$A$2:A$32))
Explanation:
When the value in A2 matches the value in the range in the second sheet it will be true and false when it does not. when True False get used in math operations they are treated at 1 and 0 respectively. Therefore the only result from your two search criteria will be the rows where A2 match is true and B2 match is true and this will have a value of 1. The 1 will then be multiplied by the row number. Since all other results will be 0 since your list is a unique combination, the sum part of sumproduct will sum up to the row number where your unique row is located. This in turn is used by the indext function to return the row to give your unique number.

If, Then, Duplicate Excel Formula

Column "A" is a numbering column for each Row, some numbers are the same, ie..
A1 is 1
A2 is 3
A3 is 1
A4 is 3
I need a formula that will show how many cells with content are in this column without counting duplicates, as above would be 2. I was figuring an "If-Then" formula but am unable to get it straight. Any help out there? Thank you in advance!
If you're using Excel 2013, I want to say that there's a count distinct function. Nonetheless, you can do it like this:
=SUM(IF(FREQUENCY(A1:A4,A1:A4)>0,1))
EDIT: Adding an explanation. The FREQUENCY function gets the frequency of the unique values within the array A1:A4 (first parameter), binning it using the values within A1:A4 (second parameter). The IF checks to see if that returns anything, i.e. if the frequency is greater than 0, in which case it returns 1 for each unique value it finds. Then the SUM adds the number of 1s returned by the IF statement, in turn giving you the number of unique values within the array A1:A4.

Check the number of unique cells in a range

I have an excel sheet.
Under column E, I have 425 cells with data. I want to check if the same data (i.e. text inside the cell) is repeated anywhere else in any of the remaining 424 cells under column E. How do I do this?
For example, in E54 I have
Hello Jack
How would I check this value to see if it was in any other of these cells?
You could use
=SUMPRODUCT(1/COUNTIF(E1:E425,E1:E425))
to count the number of unique cells in E1:425
An answer of 425 means all the values are unique.
An answer of 421 means 4 values are duplicates of other value(s)
Use Conditional Formatting on all the cells that will highlight based on this formula:
COUNTIF(E:E,E1) <> 1
This is based on the column being E, and starting on E1, modify otherwise.
In Excel 2010 it's even easier, just go into Conditional Formatting and choose
Format only unique or duplicate values
If you have to compensate for blank cells, take the formula supplied above by #brettdj and,
Adjust the numerator of your count unique to check for non-blanks.
Add a zero-length string to the COUNTIFS's criteria arguement.
=SUMPRODUCT((E1:E425<>"")/COUNTIF(E1:E425,E1:E425&""))
Checking for non-blank cells in the numerator means that any blank cell will return a zero. Any fraction with a zero in its numerator will be zero no matter what the denominator is. The empty string appended to the criteria portion of the COUNTIF is sufficient to avoid #DIV/0! errors.
More information at Count Unique with SUMPRODUCT() Breakdown.
This formula outputs "unique" or "duplicates" depending if the column values are all unique or not:
{=IF(
SUM(IF(ISBLANK(E1:E425),0,ROW(E1:E425)))
=
SUM(IF(ISBLANK(E1:E425),0,MATCH(E1:E425,E1:E425,0)))
,"unique","duplicates")}
This is an array formula. You don't type the enclosing {} explicitly. Instead you enter the formula without {} and then press cmd-enter (or something else if not a Mac - go look it up!) If you want to split your formula over multiples lines for readability, use cmd-ctrl-return on a Mac.
The formula works by comparing two SUM() results. If they are equal, all the nonblank entries (numeric or text) are unique. If they are not equal there are some duplicates. The formula does not tell you where the duplicates are.
The first sum is what you get by adding up the row numbers of every non-blank entry.
The second sum does a lookup of each nonblank entry using MATCH(). If all entries are unique, MATCH() finds each entry at its own position, and the result is the same as the first sum. But if there are duplicate entries then a later duplicate will match an earlier duplicate and the later duplicate will contribute a different value to the sum, and the sums won't match.
You might have to adjust this formula:
if you want cells containing "" to count as blank, then use LEN(...)=0 for ISBLANK(...). I suppose you could put other tests in there if you wanted, but I have not tried that.
if you want to test an array not starting at row 1, then you should subtract a constant from ROW(...).
if you have a huge column of cells, you might get integer overflow when computing this sum. I don't have a solution to that.
It's a shame that Excel does not have an ISUNIQUE() function!
This may be a simpler solution. Assume column A contains data in question. Sort on that column. Then, starting in B2 (or first non-blank cell, use the following formula:
=IF(A2=A1,1,0).
Than sum on that column. When sum = 0, all values are unique.
highlight E and on the home tab select conditional formatting > Highlight Cell Rules > Duplicate Values...
It will then highlight everything that is repeated.

Resources