Microsoft Excel getting element in previous row in the adjacent column - excel

I have a data set in Excel similar to the following:
A B
1: 07:42:07 2
2: 07:42:08 3
3: 07:42:09 4
4: 07:42:10 5
5: 07:42:11 6
6: 07:42:12 7
7: 07:42:13 8
Given a particular time, I would like to extract the value which is diagonal to the specific time. For example, given the value 07:42:10 (at cell A4), I would like to get the value 4 (at cell B3), which is in the previous row and in the next column. I need to be able to pass the time value to the function, so that the respective value in column B will be shown as explained in the example.
Is there a function which will allow me to do this please?
Thank you

Just offset the range being searched and the result range.
eg:
=INDEX(B1:B6,MATCH(G1,A2:A7,0))

Try this:
=IFERROR(INDEX($B$1:$B$7,MATCH([your time value],$A$1:$A$7,0)-1),"Out of Range")
Replace [your time value] with the value you're looking to match.
I added the IFERROR function as the value 07:42:07 would return an error otherwise.
This function will take [your time value], look for an exact match in $A$1:$A$7, and return the row number where it is found. We then subtract 1 from the row to get the previous row up (let's call it row x). Now having found our row, we ask the INDEX function to return the value from Column B, Row x.

Related

In excel how to match the given input between min and max age colums

I have an Excel file were I have 3 columns. I will explain the steps:
Step 1: I will be giving an input age (eg: 25).
Step 2: Then we need to match the minimum and maximum column .
Step 3: Once matched the value it should return from age group (eg 25-35). Multiple age groups can also be returned.
I need help with this Excel formula.
I have tried index match but no success.
There might be an easier way, but this is an option:
=INDEX($A$2:$A$8,MATCH(MINIFS($C$2:$C$8,$C$2:$C$8,">="&F33),$C$2:$C$8))
(where F33 is the cell with the age)
Explanation:
=MINIFS($C$2:$C$8,$C$2:$C$8,">="&F33)
This returns the minimum value which is greater than the given age in the table. I tried to use this function to directly return the range name, but it doesn't work; it only returns a number. So from the second range, it picks all the values which satisfy the condition, and then returns the corresponding (same row) value from the first range. E.g.: if age=52, from the second range it will pick 55 and 60 (just as filters), and then take the minimum value from the last two rows of the first range (55).
=MATCH(MINIFS(...),$C$2:$C$8)
Looks for the MINIFS result value (55) in the range and returns the row index; 6 in this case. First row is 1, and remember it's relative to the range, not the whole sheet.
=INDEX($A$2:$A$8,MATCH(...))
Just picks rows 6 from the given range.

Count B:H value based on column A value

I want to count occurrences of a value X within a range (B1:H38) only if the column A value in that row is value Y.
I got close with the following, but it gives a #VALUE! Error and I don’t think it’s the right fit for what I need:
=COUNTIFS(A1:A38,“Y”,B1:H38,”X”)
What is the correct way to do this?
Edit 1:
Column A is either blank, or one of 5 words.
Columns B through H are either blank, words, or numbers.
In my mind, the logic is: find items in A that match “Y”, then check the rest of the row from B to H for “X”.
There may be 0, 1, or up to 7 matches in a given row.
u already done it right.. it just that you formula is for 1 (one) time count.. not repeated # every row .
=COUNTIFS(A1,“Y”,B1:H1,”X”)
put that in C1, then draq downwards. That should do.
Please share if it works/not/understandable. ( :

Excel search number search in columns and rows

Would like to find out how many times (rows) between matching numbers. So if F8 has a 14, when did the next 14 come up in the range of F9:J1000. So columns and rows to do a search in. So if the next 14 is at G11, the number would be 2.
Using the exemple you provided wiht lookup value = 14 and the range = F9:J1000, you could use an array formula (this means you need to press Ctrl+Shift+Enter on Excel 2013 and earlier) to find the distance between the first and the last match using this method.
Step 1:
Create an array that return the row of the match (if there is one) or zero.
=IF(F9:J1000=14,ROW(F9:J1000)-ROW($F$9)+1,0)
Step 2:
Calculate the smallest non-zero value in that array (from step 1) using this formula:
SMALL([The array],SUM(IF([The array]=0,1,0))+1)
Step 3:
You can find the maximum value in the array using the MAX function
MAX([The array])
Step 4:
Take the result from Step 3 minus the result from Step 2 and you got the difference in row between the highest and lowest match.

2nd Smallest value based on criteria

Aim: I have all distinct names (in this case column K) and want to search down my list, column D. When I find D and K match I want to find the 2nd smallest value in E and show this value.
Code so far: =VLOOKUP(SMALL(E:E,2),D:D,1,K4)
Closest, but without Small filter =VLOOKUP($K5,$D$2:$E$999,2,FALSE)
Errors is #Value (and I can see there are actual values)
Also tried: =VLOOKUP(IF($D:$D=$K5,SMALL($E:$E,1),"X"),D:E,2) - does not filter criteia
Use Aggregate:
=AGGREGATE(15,6,$D$2:$D$9/($C$2:$C$9=$F4),2)
The 2 at the end tells the function to return the second smallest. Change that to 1 for the first.
The columns are based on your data in the screen shot. It assumes that the first column is A and the first row is 1.

Search a date in multiple date ranges and return the corresponding value

In sheet 1, I have a list of dates in Column A in chronological order. There are values corresponding to this list in Column B. There is another list of dates in sheet 2 and I want to add values from sheet 1 to these dates.
Sheet 1.
**Column A Column B
DATE Amount**
1. 10/01/2015 25,60,000
2. 10/02/2015 26,80,000
3. 01/03/2015 21,55,000
4. 30/03/2015 24,60,500
5. 30/04/2015 28,20,000
6. 30/06/2015 19,00,000
Sheet 2.
Column A Column B
1. 21/02/2015 21,55,000
2. 15/01/2015
3. 20/05/2015
4. 25/04/2015
For example: I need to look up 21/02/2015 in sheet 1 and column A and return the value corresponding to the next available date. So for 21/02/2015 I need the value corresponding to the next date available which is 01/03/2015 and the value is 21,55,000. If its 15/01/2015 I need the value of 10/02/2015 i.e. 26,80,000
What formula could I use for this?
You could use VLOOKUP, but it has some issues. So it is better to use INDEX and MATCH combination. In your case try this
=INDEX('Sheet 1'!$B:$B,MATCH(A1,'Sheet 1'!$A:$A,-1))
Sorry, my previous answer works only for descending order. Try this instead
=INDEX('Sheet 1'!$B:$B,MATCH(TRUE,('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1)),0))
Explanation: I hope that INDEX and MATCH are well explained in Office Support.
About the condition:
('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
What it means?
'Sheet 1'!$A:$A-A1
results in a difference between the value in the cell A1 and the cell in A column in Sheet 1.
MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
says that if the difference is non-negative ('Sheet 1'!$A:$A-A1>=0), find the minimum of such numbers (MIN function).
And if these numbers are equal (MATCH function), then pick the corresponding number in column B (INDEX('Sheet 1'!$B:$B,...)).
Apology: In my previous answers I swapped the columns of your example. I hope it is now correct.
You can use vlookup with True rather than the widely used form with False
As ExcelEfendisi said you can use vlookup with range lookup enabled. A simple way to get the value at the next date rather than the prior one would be to push all the amount values down one row, but to avoid that it might be better to repeat the index values - like this
1 10/01/15 25,60,000 1
2 10/02/15 26,80,000 2
3 01/03/15 21,55,000 3
4 30/03/15 24,60,500 4
5 30/04/15 28,20,000 5
6 30/06/15 19,00,000 6
Then you can use two vlookups, the first one to get the index of the row with the date prior to the date you are interested in and a second one to extract the balance value for the subsequent date - not very elegant but it would work
Try this formula (enter in Sheet2 cell B2 then copy till the last record)
=INDEX(Sheet1!$B:$B,1+MATCH($A2,Sheet1!$A:$A,1),1)
As data is sorted in ascending order use MATCH with match type 1 (less than) to obtain the row above the high next item, then add 1 and the result is the high next row, use this row to get the corresponding record from the column B with formula INDEX

Resources