Combining LOOKUP and OFFSET - excel

I would like to offset the last entry in my data by one week. For example, I just created this example data:
day value
1 4
2 3
3 5
4 6
5 1
6 3
7 9
8 5
To find the last entry in the dataset, I use the lookup function:
=LOOKUP(9.99E+307,b1:b10)
which will return the value 5. (In case that notation is not familiar, 9.99E+307 is the largest number that can be written in Excel).
I would like then to compare this value to last week's value, and thus offset the last entry by 7. I see that OFFSET asks for: offset(reference,rows,cols) but using:
=OFFSET(LOOKUP(9.99E+307,b1:b10),-7,0)
does not seem to work (it returns an error).
What could be the problem?

#user3561813 has explained why, a solution might be:
=INDEX(B:B,MATCH(1E+100,B:B)-7)
MATCH finds the position (row number) of last entry in ColumnB, -7 steps up seven rows and INDEX finds the content of that row in ColumnB.

You could also use a single LOOKUP function with the "return vector" offset by 7 rows, e.g.
=LOOKUP(9.99E+307,B8:B100,B1:B93)

Why not change the lookup to look for the last day in the list?
This formula will return the last day value (8 in your data above):
=LOOKUP(9.99E+307,A1:A10)
You can then use this formula to return the last value for that day (5 in your data above):
=VLOOKUP(LOOKUP(9.99E+307,A1:A10),A1:B10,2,FALSE)
If you wanted to get the value for 7 days earlier just subtract 7 from the results of the LOOKUP formula like this (will return 4 - day 1 value in your data above):
=VLOOKUP(LOOKUP(9.99E+307,A1:A10)-7,A1:B10,2,FALSE)

The Reference is the OFFSET function refers to a Range object (a cell). The result of your Lookup function is a numeric value, in this case 5. You can't OFFSET a numeric value.
Have you considered using VBA?

Related

How to find the difference in values for each entry in one of the columns

What formula could I use to find the Average difference for each time there is an entry for column B.
For example in the excerpt below the average would be 7. We would only use rows 2 and 3 because there is an entry in them. If I can I would like to avoid using VBA.
Submitted
Returned
10/2/2022
10/3/2022
10/9/2022
10/17/2022
10/25/2022
10/25/2022
10/9/2022 - 10/3/2022 = 6
10/17/2022 - 10/25/2022 = 8
(6 + 8) / 2 = 7
I tried finding a for each function in excel and I tried using =Average(B-A)
You have several options. Using AVERAGE, you can use the following in cell D1:
=AVERAGE(IF(B2:B5-A2:A5 < 0, "", B2:B5-A2:A5))
This function ignores empty values ("") as part of the average (but AVERAGEA doesn't). The resulting array of IF statement will be the difference in days of the Returned value and the Submitted value if the Returned is not empty, otherwise, it will be an empty string. Empty dates are represented in Excel as 0 and any other non-empty date is a positive number, so B2:B5-A2:A5 < 0 meets our requirement.
Another alternative is to use SUMPRODUCT (in cell D2):
=SUMPRODUCT(B2:B5-A2:A5,--(B2:B5>0))/COUNT(B2:B5)
Note: You cannot use AVERAGEIF or AVERAGEIFS with the input argument: B2:B5-A2:A5 because it is not a range and the first input argument is required to be a range.
Here is the output:

Using an average of 10 rows for multiple cells, then moving to the average to the next 10 cells

I have a large column of data where every 10 rows is a different set.
What I would like to do is get the average of those 10 rows, and then subtract that from every individual measured value.
Then it moves to the next 10, takes the average of those, and subtracts it from the 10 data points that yielded the new average.
I've tried using MOD and plenty of formulas and dragging out some kind of formula but Excel's pattern recognition is not working at all in this case.
Example of what I'm trying to do using 3 values instead of 10
The output I want takes the average of the first 3 values ((1+2+3)/3=2), then subtracts it from those 3 values and outputs it as the result. (1-2=-1, 2-2=0, 3-2=1). Then it repeats the same thing with the next 3 and the results from the previous 3 do not affect it.
Values________Average_______Result
1|__________________________-1
2|______________2 __________ 0
3|__________________________1
2|__________________________-2
5|______________4 __________ 1
5|___________________________1
2|___________________________-1
5|_____________3_____________2
2|___________________________-1
(I'm so sorry about the awful table)
Any help would be greatly appreciated! Thank you.
Using your data and doing every three:
=A2-AVERAGE(INDEX(A:A,INT((ROW(1:1)-1)/3)*3+2):INDEX(A:A,INT((ROW(1:1)-1)/3)*3+4))
To change to 10 change the each /3 to /10 and *3 to *10 this is the interval. You will also need to change the +2 to the first row of data and the +4 to +11 or +[the interval]-1
I like Scott's answer better, but since I had worked it out while he was typing, I'll add my solution as well.
I'm using the INDIRECT function to build the range reference and calculating the range for the AVERAGE by using MOD on the ROW function.
Basically you're looking to average over the first ten rows, so you need the range A1:A10, then A11:20, and so on. In order to calculate the beginning row, take your current ROW() and subtract the MOD 10 of its previous row: ROW()-MOD(ROW()-1,10). The last row of the group just adds 9 rows: ROW()-MOD(ROW()-1,10)+9.
Everything in Column B uses the formula:
=AVERAGE(INDIRECT("A"&ROW()-MOD(ROW()-1,10)&":A"&ROW()-MOD(ROW()-1,10)+9))

Microsoft Excel getting element in previous row in the adjacent column

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.

How to return values from previous day or month?

I have a list of data for the month of feb and I want to return values of only those days for which data has been recorded.
Ex:
Defect 02/01 02/02 02/03 02/04
Missing clip
Wrong cable 3 5
Wrong BSN 5 9 6
Damaged harness 4 2 1
I want the formula to return the values and defect type for the date of 02/02
I want the formula to return only Wrong BSN and Damaged harness and the corresponding values for that.
Any help would be appreciated.
Thanks,
Kavya
You can use =HLOOKUP() to horizontally search for a specific term, and when the formula find the term, it'll return the occurrence in the nth row.
=HLOOKUP(what_ur_searching, where_ur_searching, which_row_should_return, exact_or_aprox_match)
It's important to say that HLOOKUP will match the first occurrence from left to right. In your example you have 02/03 two times, so if you try to return the 02/03 values, it'll return 9 and 1, instead of 6 and null.
Wrong BSN:
Write the following formula in any cell that you want, inside the same worksheet: =HLOOKUP("02/02",$A$1:$E$5,4;0)
Explaining:
Search in the first row of $A$1:$E$5, the occurrence of the term "02/02". If the formula find it, return the occurrence on the 4th line (where 1 is equal to the header and 4 is equal to the row number of "Wrong BSN" data). The 0 means that it's looking for the EXACT occurence of "02/02".
Damaged harness:
Write the following formula in any cell that you want, inside the same worksheet: =HLOOKUP("02/02",$A$1:$E$5,5;0)
Explaining:
Search in the first row of $A$1:$E$5, the occurrence of the term "02/02". If the formula find it, return the occurrence on the 5th line (where 1 is equal to the header and 5 is equal to the row number of "Damaged harness" data). The 0 means that it's looking for the EXACT occurence of "02/02".

Multiple conditions- if value between range display corresponding value

I tried to figure it out by myself and with the internet but I need your help.
I need to check a value is in few ranges and assign in the cell the corresponding value:
* all the numbers are integers
If the value is 0, display 1
if the value between 1 to 3, display 2
if the value between 4 to 6, display 3
if the value between 7 to 10, display 4
if the value is above 10, display 5
Tnx
IF Function
=IF(B2=0,1,if(B2<=3,2,if(B2<=6,3,if(B2<=10,4,5))))
This assumes the value you are checking is in B2 AND that it is a positive integer (ie, no -1 or 1.5)
VLOOKUP Function
=VLOOKUP(B2,$F$2:$G$6,2,1)
B2 value you are checking
F2:G6 is the table of break points (F) and values to be displayed (G)
Build a table with the first column being your break points and a column adjacent to it being the values you want to display. In this case your breakpoints would be 0,3,6,10 and we need to add 11 for the values greater than 10. This method assumes positive values and with the exception of the 11 breakpoint could be used for decimals as well as integers. The current problem is values between 10 and 11 would display as 4 instead of 5.
Two more alternatives if you wanted to do it with a single formula without a separate lookup table:-
=MATCH(A2,{0,1,4,7,11})
=HLOOKUP(A2,{0,1,4,7,11;1,2,3,4,5},2)
Syntax:
=COUNTIFS(Range, "condition1", Range, "condition2")**
Example (finding total numbers lies between 25 to 21 in range J9:J110)
=COUNTIFS(J9:J110, "<=25", J9:J110, ">=21")**

Resources