I don't use excel often, and I haven't really found a good solution to my problem. (which is probably really simple).
I would like to have a cell with a function in my spreadsheet that shows another cell value value that depends on yet another cell value.
Such as:
The Best Deal heading simply uses the formula
=MAX(D3,D1000)
But under Best Deal I would like to display the Name Test1 rather than the numeric value.
Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))
Obviously that function wouldn't work as I wrote it, but hopefully this pseudo code gives you an idea of what I mean. The purpose is that if more entries are added, it would be able to handle them.
I know this is possible, but I'm having some trouble. Hopefully I can get some help here.
Thanks!
The easiest way to do this is to use a combination of Index and Match. Match will find the position of the maximum value, and then Index will look in column A and return the data in that same position. So, your formula would be:
=INDEX(A$3:A$1000,MATCH(MAX(D$3:D$1000),D$3:D$1000,0))
Put that formula in F3. No hidden columns required.
Sorry, I missed the part about the expanding range. You can do that by using Count or CountA along with Offset. The new formula would be:
=INDEX(A3:OFFSET(A3,COUNTA(A:A)-1,0),MATCH(MAX(D3:OFFSET(D3,COUNT(D:D)-1,0)),D3:OFFSET(D3,COUNT(D:D)-1,0),0))
More complex, but it is basically the same except that it will expand as you add new values at the end.
There is only one 'simple' way I can think of this, but it requires hidden columns (sorry).
set E1 = A1 and fill down all the way (Basically you are making a copy of column A in column E but you are using a formula so it will always be the same)
Then under 'Best deal' - put this formula:
=VLOOKUP(MAX(D3,D1000),$D:$E,2,FALSE)
Then hide column E so it doesn't look like a mess. This way you do not need any fancy macro's and it will work everywhere because it is a normal formula.
"Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))"
This is a called a dynamic named range. Create a name for the ratio data, and set up the formula for the name range to be this:
=OFFSET($D$3, 0, 0, COUNTA($D$3:$D$1048576), 1)
More info here: http://www.ozgrid.com/Excel/DynamicRanges.htm
Then, assuming you name this named range ratio_data, your function could be referring to =MAX(ratio_data) in combination with index-match as suggested by #Tim Mayes. The range will expand automatically as you add more data.
=INDEX(A$3:A$1000,MATCH(MAX(ratio_data),ratio_data,0))
Ideally, you can replace the A3:A1000 by a dynamic named range as well.
Related
I have scoured the internet but come up empty.
I am looking for a formula that will be in a single cell (I don't want to have to fill it down the side of the table for instance) that will return the header of the first column that has a value in it, from left to right. If there's a value in the last cell of the first column, for instance, I want that header returned rather than moving to column 2.
I have tried nested xlookups and index/match combinations and just can't find anything that will be in a single cell.
Any help is appreciated!!
EDIT: Yup, let me be more clear. My apologies!
Here is an excerpt of my table. In this instance, I would want the result to be Sep-21 (a reference to the cell is also fine).
I know I can easily drag the formula in A1 down and pull the column header of the first cell in that row with a value. What I want is to reference this on another sheet, so I don't want to have to do that. I want one formula in one cell to pull this information, if possible. If I can't do it that simply, maybe I have to do some other wizardry and hide a row/column or something and fill the formula down that way and then pick the latest date, but I'd like to avoid that if possible. One cell would be much more elegant!
As for what I've tried, all my attempts are pretty messy and incomplete, so I don't know if it would be helpful to paste them here, but essentially I've tried to use an xlookup where the lookup_array is B2:D6, and then the return_array is the header, but that doesn't seem to work. I guess the lookup_array has to be a single column/row? Something like:
xlookup(ISBLANK(FALSE), B2:D6, B1:D1)
It's kind of like an inverse xlookup, lol.
EDIT2: I've done some more messing about and have come SO CLOSE! Now my problem is with structured references in a table and trying to exclude my first two columns.
First, the solution that does work without structured references (assuming the table starts in A1):
=IFERROR(INDEX(B1:D1,SUMPRODUCT(MIN(IF((B2:D6<>0)*(COLUMN(B2:D6)) > 0, ((B2:D6<>0)*(COLUMN(B2:D6)))))-COLUMN(A1))), "error")
But like I said, my structured references are getting in the way now. I want to pull all the data in my dynamic table, except for the first two columns.
I know this is a completely different problem now, my apologies for that.
The solution (assuming the table starts in A1):
=IFERROR(INDEX(B1:D1,SUMPRODUCT(MIN(IF((B2:D6<>0)*(COLUMN(B2:D6)) > 0, ((B2:D6<>0)*(COLUMN(B2:D6)))))-COLUMN(A1))), "error")
If your data is in row 2:
=INDEX(1:1, 1, MATCH("", 2:2,-1))
should work
I am a programmer, so please bear with me. I understand that Excel isn't necessarily what I am used to in other domains, but I'm cracking my head open on how to accomplish something that seems somewhat simple.
I have a column of numbers that are themselves the basis of a formula. I want to filter those cells based on some criteria and pass them to another function to perform a calculation.
I understand that this can be done with "filters" in the excel sense. This would mean I would have to click multiple times for each calculation, filter the results, copy the value and paste it where I need it to be. If the data ever changes, I will have to do it all again.
What I am looking for is the equivalent of filtering in a programming language, here's an example:
let range = [1,2,3,4,0,-1,-2,-3,-4];
let subrange = range.filter(function (cell) { return cell > 0; });
subtotal(1,subrange);
So what my excel is like.
I have a column G, that has 12,000+ results in it, each one of these columns is like this:
=(En-Bn)/Bn
These are copied down, n means the row number from 5-12,000+
Now I would like to create a cell, M2 such that it contains:
=SUBTOTAL(1,[ Gn in G5:G12000 where Gn > 0 ])
The goal is that I do not want to have to point and click, because actually, there are many more cells I need to create (about 20) with similar kinds of "filter" predicates.
It would be nice, as much as possible, if I also don't have to specify the n...n-1 range of the column, as ideally that can change. Could be 10, could be 20,000, shouldn't matter.
The best formula or solution would be like:
SUBTOTAL(1, [ Gn in G0:GLENGTH where Gn > SOMECELL ])
Any pointers, or suggestions where to read, or a solution would be awesome. I've been searching on google, and it seems that I lack the right understanding to find the answer in the material presented.
Also, please excuse me for using programmer speak, I know that Excel formulas are not necessarily a 1:1, I'm just looking for a way to save time. Answers in VBA or using Macros are welcome, the main thing is to find a way to do it...
Best,
Jason
Update
I should specify that it needs to be a bit backwards compatible, so I can't use the FILTER function that is only available in >= 365
I'm not at all sure that your attempts at saving time by talking in programming language instead of English really saves either time or space. My best effort determines that you got us all confused. Please tell me why the simple formula below doesn't work.
=AVERAGEIF(G2:G15000,">"&A1,G2:G15000)
This formula requires A1 to hold a number and the formula supplies the > sign. A variation would have A1 contain both, number and comparison, like >1.2`
=AVERAGEIF(G2:G15000,A1,G2:G15000)
The above formulas start the range at G2. Change to G5 if that is what you need. G15000 is a random number intended to be larger than anything you will ever need. The function ignores blanks. However, if you are worried about having a sheet with 16000 rows just on the day you forgot where to adjust the formula I would recommend the use of a named range which you could format to be dynamic.
Named ranges are neater to handle than range addresses and names can be given descriptively, such as HourlyReadings. The above formula would then look like this:-
=AVERAGEIF(HourlyReadings, ">"&A1,HourlyReadings)
Theoretically, the formula by which HourlyReadings is defined could also be written into the worksheet formula but it would become unwieldy. As shown above, you would have to look into the Name Manager to know if the range is dynamic or not but, of course, once defined you can use the same name in many functions and formulas which saves a lot of maintenance time.
This is for Excel 365, using worksheet formulas. With data in column G starting in G5, in another cell enter:
=SUM(FILTER(G:G,G:G>0))
How about an array?
=SUM(IF(G:G>0,G:G,""))
put cursor in 'function bar' with formula. Then press CTRL+SHIFT+ENTER (in that order while holding them all down. {} will appear around formula.
Let me know if further assistance is needed.
Matt
I have a long list of part numbers where I need to be able to lookup and retrieve information on them.
These parts can have several alternative part numbers. I have figured out how to get the data returned if my data table only shows one of the possibly part numbers.
The issue is that I want it to be able to look up the columns to find a matching value.
As in the picture below for example. 5-E26 is the equivalent to E5-25. So if I input 5-E26 in the cell, I want it to continue searching to find the value in B7, and return the data as done A4 and A5.
Is this possible to do with Vlookup? Or is there a smarter method for it?
I struggle to fully understand how your data works but here is a possibility:
So the translated version of the formula I used in G2:
=INDEX($D$1:$D$5,AGGREGATE(15,3,((($A$2:$D$5=F2)/($A$2:$D$5=F2))*ROW($A$2:$A$5)),1))
You could also try (in my case):
=INDEX($D$1:$D$5,SUMPRODUCT(($A$2:$D$5=F2)*ROW($A$2:$D$5)))
So, I have an Excel-file with two sheets. The first sheet contains 7 Columns of different values.
The second sheet contains a list of special customer prices.
What i want to do, is basicly search for the value given in e.g. cell A2, in Sheet2!A:A. If i were to find this value (it's a text value), I want to return the value located in that spesific row containing the value searched for, only 3 colums to the right.
I've done a lot of experiments, but really can't get INDEX and MATCH to do the work properly for me. Anyh suggestions?
Feel free to ask for more information, as I know I can be a challange to understand..
Best regards
try offset() and match(), offset(reference,rows,cols). use match to find the number of rows or columns to move from the reference point.
Using OFFSET is against almost all best practice guides. It is a volatile function, meaning it should be avoided at all costs. Use INDEX+MATCH instead. It can do all the same stuff but has much better performance.
=INDEX(column holding the value you want to return, match to find row #, 1)
=MATCH(value you are looking for, column you are searching in, 0 means exact match)
Result:
=INDEX(Sheet2!$D$2:$D$10,MATCH(A2,Sheet2!$A$2:$A$10,0),1)
I believe the function you are looking for is a vlookup. Try this:
=vlookup(A2, Sheet2!A:D, 4, 0)
Regards,
Windyvation
Currently I am trying to set up a dynamic range using this formula structure:
=OFFSET($A$2,,,COUNTA($A:$A)-1)
I then modified the formula to find a keyword in the header row:
=OFFSET($A$2,,MATCH("THIS",$1:$1,0),COUNTA($A:$A)-1)
My issue is the COUNTA statement at this point. I want to type something like COUNTA(COLUMN(MATCH("THIS",$1:$1,0))) but it doesn't appear to be this simple.
Instead my workaround is something to the effect of:
COUNTA(INDIRECT(LEFT(ADDRESS(1,MATCH("THIS",$1:$1,0)),2)&":"&LEFT(ADDRESS(1,MATCH("THIS",$1:$1,0)),2)))-1
The entire formula becomes rather long and cumbersome, and I have a feeling that I might be missing something to simplify it. Is there an easier way to do this that would be similar to simply evaluating to COUNTA(Column(10)) or is my approach the most efficient method?
Try this definition
=OFFSET($A$2,,MATCH("THIS",$1:$1,0)-1,COUNTA(OFFSET($A:$A,,MATCH("THIS",$1:$1,0)-1))-1)
The second OFFSET gets the whole column