Integrating number in between range with a vlookup - excel-formula

I am working with a data table that contains two columns ( Max Room Height, # of bulbs). Intent is to create a formula which provides the output on # of bulbs to use after the user inputs room height. Here’s the trick, room height number that user inputs can be a random number, and could lie between two max room heights. For example , room height data is available as 10 feet, 12 feet, 14 feet, 16 feet and the and user inputs room height as 15 feet, formula should be able to pick up the # of bulbs corresponding to 16 feet height.

You can try using some of the built-in Excel functions to determine the number of bulbs to use based on the room height. Here's an example using INDEX(...), MATCH(...), and MIN(...):
I do not have access to Excel at the moment, but this worked in LibreOffice Calc v5.1.6.2. Excel seems to have comparable functions.
Long Winded Explanation
Read on, in case a picture is not worth a thousand words!
Table/Data Configuration
Create a table with two columns (Columns E and F in the example image).
The first column (Column E) represents the upper height boundaries in descending order. Note the upper bound of 10000.
The second column (Column F) represents the number of bulbs to use if a given room height falls within the height boundary.
So for this example, values between 10000 (inclusive) and 16 (exclusive) should state to forget light bulbs and just use the sun. Values between 16 (inclusive) and 14 (exclusive) should state to use 4 bulbs. Values between 14 (inclusive) and 12 (exclusive) should state to use 3 bulbs... etc.
Create a second table that has two columns for the data and results (Columns A and B in the example below; Column C is for illustrative purposes only).
The first column (Column A) will contain the "user input" (i.e. variable Room Heights whose number of bulbs should be looked up).
The second column (Column B) will contain the formula to calculate the number of bulbs to use based on the "user input" and the height boundaries defined in the first table that we created.
Formula/Calculation
Let's break down the formula that will go into the Column B cells. I left the text for the formula in Column C. You'll notice that only the first parameter of the MIN(...) function changes for each row. The rest of the formula is the same for each row.
Using row 2 as an example, we make use of 3 functions, nested together:
MIN(A2,E2) - We want to make sure the room height falls within our handled range. This works in conjunction with the the arbitrary upper bound of 10000 that was added to Column E. If we didn't force the data to fit within the upper boundary, we'd probably see some kind of error if the user exceeded the largest value specified in Column E.
MATCH(MIN(A2,E2),E2:E6,-1) - Essentially, this function finds the height range boundary under which the user entered data falls. This function has three parameters. The first is the user entered data (or the arbitrary upper bound)... MIN(A2,E2) for this row. The second is the height range boundaries (in descending order)... E2:E6. The third is the matching type... -1. The matching type of -1 means "search a descending list of values and stop when your given value (i.e. the first parameter) is equal to or less than a value in the descending list". If the first item in the descending list meets the criteria, the MATCH(...) function returns an index of 1. If the second item in the descending list meets the criteria, the function returns an index of 2... etc.
INDEX(F2:F6,MATCH(MIN(A2,E2),E2:E6,-1)) - This function essentially looks up our "answer" for the user's input. We found the "index" or "list position" of the height range for the user's input using the MATCH(...) function and we created our table such that the bulb-count for each height range is in the same row (i.e. it has the same "index" or "list position"). The INDEX(...) function accepts two parameters. The first is the range of cells containing the "answers"... F2:F6. The second parameter is the index or list position from the answer cell range that we want to return (i.e. the results of our MATCH(...) function). So if our MATCH(...) function call returns "1", the first cell from the F2:F6 range will be returned (i.e. F2 - Use the Sun!). If our MATCH(...) function call returns "2", the second cell from the F2:F6 range will be returned (i.e. F3 - 4 bulbs)... etc.
There might be better solutions out there depending on the version of Excel you are using. According to the Office documentation as of this writing, the functions used here should be valid for Excel 2007 through 2016.

Related

How to find the 3 highest values and respective category for a cell

Here is an example of the data I'm trying to organize:
I'm looking for a way to automatically see the top 3 categories (column) for each Name# (row). The size of the category is determined by the number below the category.
Ideally, I'd also like to see a percentage breakdown (from the total) for each category. For example, in row "Name3" 2 categories make up a significantly larger portion of the total values. However, without this percentage breakdown, the 3 top values would seem to be comparable, when they are in fact, not.
Interested to see how this would all work with duplicate numbers, too.
I've tried Excel's rank function, but this doesn't tell me the categories that have the 3 largest sizes, just the 3 highest values.
With Office 365:
=FILTER(SORTBY($B$1:$H$1,B2:H2,-1),SORT(B2:H2,1,-1,TRUE)>=LARGE(B2:H2,3))
And copy down.
If there are ties it will expand the results to include it. It finds the third highest value and returns everything that is equal to or greater than it.
This approach spills all the results at once (array version). In cell J2, you can put the following formula:
=LET(D, A1:H5, A, TAKE(D,,1), DROP(REDUCE("", DROP(A,1), LAMBDA(ac,aa,
VSTACK(ac, TAKE(SORT(DROP(FILTER(D, (A=aa) + (A="")),,1),2,-1,1),1,3)))),1))
It assumes as per input data the cell A1 is empty (if not it can be adjusted accordingly). Here is the output:
An alternative that doesn't require previous assumption (but it is not really a hard one) is the following:
=LET(names, A2:A5, Data, B2:H5, colors, B1:H1, DROP(REDUCE("", names,
LAMBDA(ac,n, VSTACK(ac, TAKE(SORT(VSTACK(colors, INDEX(Data, XMATCH(n,names),0))
,2,-1,TRUE),1,3)))),1))
The non-array version can be obtained from previous approach, and expand it down:
=TAKE(SORT(VSTACK($B$1:$H$1,INDEX($B$2:$H$5, XMATCH(A2,$A$2:$A$5),0)),2,-1,TRUE),1,3)
Explanation
To spill the entire solution it uses DROP/REDUCE/VSTACK pattern. Check my answer to the following question: how to transform a table in Excel from vertical to horizontal but with different length.
For the first formula we filter for a given element of A name (aa) via FILTER the input data (D) to select rows where the name is empty (to consider the header) OR (plus (+) condition) the name is equal to aa. We remove via DROP the first column of the filter result (names column). Next we SORT by the second row (the first rows are the colors) in descending order (-1) by column (last input parameter of SORT we can use TRUE or 1). Finally, we use TAKE to take the first three columns and the first row.
For the second approach, we select the values for a given row (names equals n) and use INDEX to select the entire row (column index 0), then we form an array via VSTACK to add as first row the colors and use the similar logic as in previous approach for sorting and select the corresponding rows and column (colors).
Notes:
If you don't have VSTACK function available, then you can replace it as follow: CHOOSE({1;2}, arr1,arr2) and substitute arr1, arr2, wit the corresponding arrays.
In the second formula instead of INDEX/XMATCH you can use: DROP(FILTER(Data, names=n),,1), it is a matter of personal preference.

Function to search for specific number and then to further search for the prefix

I have a huge amount of data to process in which 4 points with a related prefix needs to be subtracted from each other.
Data consists of ID and x value
Example
ID = 290.12, 290.03, 290.06, 290.09, 300.12, 300.03, 300.06, 300.09, 301.12, 301.03, 301.06, 301.09
(let's call prefix a "ring number" and suffix time on the clock)
X value = any numerical value for each ID assigned
What I'm hoping to do is to search for the first number before the dot i.e. 300 and then subtract the value of 300.06-300.12 in one cell and in another cell 300.03-300.09.
(The subtraction is just an example, how I need to manipulate with the numbers is slightly more complicated, but I got this one under control)
This is my actual Data and what I need to produce is to the right of the raw data. At the moment, I'm doing it manually for each set of "rings"
Anyone knows how to approach this? I'm thinking vlookup, but I'm not very proficient in excel.
New Excel
I tried vlookup, but I don't know how to construct the formula and I run out of ideas.
Edit:
I found out that REDUCE is no requirement in this case, so it can be shortened to:
=SQRT(SUM(((INDEX(B:D,XMATCH(I3+0.09,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(I3+0.03,A:A),SEQUENCE(1,3)))^2)))
You could change +0.09 and +0.03 to your needs and may reference them using LET() for easy maintaining:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
SQRT(SUM(((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2))))
Previous answer:
=LET(
id,I3,
_id1,0.09,
_id2,0.03,
SQRT(
REDUCE(0, SEQUENCE(1,3),
LAMBDA(x, y,
x+((INDEX(B:D,XMATCH(id+_id1,A:A),y)
-INDEX(B:D,XMATCH(id+_id2,A:A),y))
^2)))))
This formula looks for the matching value of the id value I3 + _id1 minus the matching value of id value + _id2 for columns B to D and adds the ^2 results per column. Then it calculates it's square root.
You can change _id1 and _id2 to your needs.
To calculate the Delta (as shown) at once you could use:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
_id3,0.12,
_id4,0.06,
x,SQRT(SUM((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2)),
y,SQRT(SUM((INDEX(B:D,XMATCH(id+_id3,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id4,A:A),SEQUENCE(1,3)))^2)),
(x-y)*1000)
You can have a column of unique values of the integers and a new column where you reference these values as id and drag down the formula to get your row by row result
In another column you can refer to these columns and sort per the second column using SORTBY()

What function can I pass to determine the point score in Excel?

I am trying to calculate the point score for which matches the findings column from the data. There are many different sections since there are different categories within the data. What kind of forumla could I use to determine the score based on the different categories? I considered use vlookup but that only works for the first section of the point data.
The objective is to return either 0,1 or 2 based on the category of the data such as media and the finding values
Excel Data
You can use a combination of INDEX, MATCH and OFFSET, with a helper row:
For formula I'm using there is as follows:
=INDEX(OFFSET(INDEX($A$2:$A$12,MATCH(C18,$A$2:$A$12,0)),3,1,1,3),MATCH(B18,OFFSET(INDEX($A$2:$A$12,MATCH(C18,$A$2:$A$12,0)),2,1,1,3),1))
OFFSET(INDEX($A$2:$A$12,MATCH(C18,$A$2:$A$12,0)),3,1,1,3) this part gives the range for points matching the category. I use something similar to get the range matching the points.
First, INDEX and MATCH gives the cell containing the category. I use OFFSET to move that reference 3 cells down, 1 cell right, keep the height and increase the width to 3. For instance, in D2, INDEX and MATCH gives me cell A7. Offsetting that using the values I mentioned earlier means that the result of offset will be the range B10:D10.
Using the same logic, I get the range B9:D9. From that range, I use MATCH to get the highest column in which the value in range B9:D9 is smaller than the listing value, in this case the value 100 is the largest value that is smaller than 165, so I get the result 3 from MATCH. This fed into INDEX gives the corresponding points.
But you can do without OFFSET if you can picture the different arrays in your head using only INDEX and MATCH:
=INDEX($B$5:$D$15,MATCH(C18,$A$2:$A$12,0),MATCH(B18,INDEX($B$4:$D$14,MATCH(C18,$A$2:$A$12,0),0),1))

Retrieve the cell reference of the first non-blank cell in a column

I have a data set (discrete monthly return series) with two dozen columns representing data series, c.100 rows representing month-end time-series. The data in the set represents the monthly performance of each data set.
Each series has run for a different length of time and is updated to a different length of time.
My conundrum is; I am looking to find, for each series, the dates of both the earliest data point and the most recent data point. I was hoping to do this by way of referencing the row headers (date) in column A. To do this I would need to know the row number of the earliest data point.
I can get the value of the earliest data point using a CSE IndexMatch, but what I really need is the reference.
EDIT
Tom, this is the data set;
As you can see, each data set starts (and finishes) at a different date.
In a summary sheet I am putting the date range for which each respective data series has data, that is why I need the row value (so that I can lookup the dates).
So your formula was fine, you just needed to MATCH in column G and INDEX into column A:-
=INDEX('Discrete Monthly Returns'!A3:A1048576,MATCH(FALSE,ISBLANK('Discrete Monthly Returns'!G3:G1048576),0))
I appreciate that you would want the start date to appear somewhere else, but this is just an illustration of how to use the formula
This example teaches you how to find the cell address of the maximum value in a column.
First, we use the MAX function to find the maximum value in column A.
Second, we use the MATCH function to find the row number of the maximum value.
Explanation: the MATCH function reduces to =MATCH(12,A:A,0), 7. The MATCH function returns the position of the maximum value in column A. Set the third argument to 0 to return an exact match.
Finally, we use the ADDRESS function to return the cell address.
Explanation: the ADDRESS function reduces to =ADDRESS(7,1), $A$7. The first argument specifies the row number. The second argument specifies the column number.
http://www.excel-easy.com/examples/locate-maximum-value.html
The answer is copy-paste work from the above link, but pasted here as reference.

Select a cell value from a range based on criteria

I'm trying to figure out a sleeker method for determining the value of a cell based on criteria defined in a given range. To put it bluntly, I have a column for standard viscosity, standard temperature, and measured temperature. I'm needing to create a fourth column that will select the standard viscosity based on the measured temperature. For example, if measured temperature is greater than or equal to 0oC and less than 1oC: return standard viscosity for 0oC.
My issue is that I have a large range and find it to tedious to create a custom expression for each range. I've created a nightmarish function that was composed of IF(AND()) statements but find this exhausting, especially if I try to create an expression for a 0-200oC scale in single digit increments.
Here is a sample of a code that works but is quite cumbersome:
=IF(AND(G8>=$C$7,G8<$C$8),$D$7,0)+IF(AND(G8>=$C$8,G8<$C$9),$D$8,0)+....
or
=IF(AND(measured temp>=0,measured temp<1),$D$7,0)+IF(AND(measured temp>=1,measured temp<2),$D$8,0)
How could I approach this in a sleeker manner?
You can achieve this by the VLOOKUP function.
=VLOOKUP(G8;$C$7:$D$...;2;TRUE)
Replace the three dots with the index of the last row of your table.
The first argument of VLOOKUP is the value to search for; the second argument is the range whose first column is to be searched for the value; the third argument is the index of the column containing the values to return (within the range, so 2 means the second column within the range, which is D in your case); TRUE means that you do not want to search for an exact match, but that the column to be search is an ordered list of values defining intervals.
Edit:
With MATCH and OFFSET (guessed, not tried), if column with result values is left relative to column of criterion values:
=OFFSET($C$7;...;MATCH(G8;$C$7:$C$...;1) - 1)
Replace the first three dots with the position of the result column, relative to column C (so 1 if it's column D, and -1 if it's column B), and the second three dots with the index of the last row of your range, as above.
Edit2:
INDEX instead of OFFSET is even better, se pnuts's answer and the comment below:
=INDEX($D7:$D...;MATCH(G8;$C$7:$C$...;1))
If your measured temperature is say in F2 and your data table is A:C please try:
=INDEX(A:A,MATCH(F2,C:C))

Resources