Excel formula not working as expected - spreadsheet

I have a sheet that shows max values spent anywhere. So I need to find most expensive place and return it's name. Like this:
Whole sheet.
Function.
Function in text:
=IFS((A6=MAX(D2:D31)),(INDEX(C2:C31,MATCH(A6,D2:D31,0))),(A6=MAX(H2:H31)),(INDEX(G2:G31,MATCH(A6,H2:H31,0))),(A6=MAX(K2:K31)),(INDEX(K2:K31,MATCH(A6,L2:L31,0))))
Basically I need to find a word left to value, matching A6 cell.
Thanks in advance.

Ok.. Overcomplicated!
Firstly, why the three rows? it's a lot easier if you just have one long row with all the data (tell me if you actually need 3 I'll change my solution)
=LOOKUP(MAX(D2:D31);D2:D31;C2:C31)
The MAX formula will lookup the biggest value in the list, the Lookup formula will then match it to the name.
Please note: If more than one object has the maximum price, it will only return the first one. The only way I can think of to bypass that would be to build a macro.
EDIT:
Alright.. Multi Column solution is ugly and requires extra columns that you can just hide.
As you can see you'll need 2 new columns that will find the highest for each row, 2 new columns that will find the value for each of these "highest" (in this case tree and blueberries) and then your visible answer will simply be an if statement finding out which one is bigger and giving the final verdict. This can be expanded with an infinite number of columns but increases complexity.
Here are the formulas:
MAX(H2:H31)
LOOKUP(A5;H2:H31;G2:G31)
MAX(L2:L31)
LOOKUP(C5;L2:L6;K2:K6)
IF(A5>C5;B5;D5)

Related

How to randomly distribute a known group of numbers into a column using Excel / VBA

I'm stuck with excel/vba:
I've got a 10 row x 30 column blank array in Excel. I am trying to distribute 10 integers from a known group of 10 (say 1,1,1,1,1,1,3,5,7,9) into each column randomly so that each row of the column contains one of the group (and all of the group members are used once), and I need the second column to contain another random distribution of the same group and so on.
So I'd end up with 30 columns of 10 rows each, with each column containing a different random distribution of the same 10 integers. I want to be able to change the distribution in each row by recalculating the spreadsheet too.
Is there a quick way to do this? Short of arranging 30 different rand() sorted lists and using lookups I couldn't see a way. I'm not savvy enough with VBA to have a go. If someone can point me in the right direction, I'd be eternally grateful!
Perhaps I'm missing something obvious, though this does not seem to be so straightforward using worksheet formulas alone.
If your orginal list of values is in A1:A10, then, in B1:
=INDEX($A$1:$A$10,RANDBETWEEN(1,10))
and in B2, array formula**:
=INDEX($A$1:$A$10,INDEX(MODE.MULT(IF(COUNTIF($A$1:$A$10,$A$1:$A$10)-COUNTIF(B$1:B1,$A$1:$A$10),{1,1}*ROW($A$1:$A$10))),RANDBETWEEN(1,10-ROWS($1:1))))
Copy the above down to B10.
You can then copy the formulas in B1:B10 to the right as desired.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
You could make a loop in which you make an array with your 10 numbers. Then loop though 30 columns, with first adding another column of 10 randomly drawn numbers to your array. See this website on how to draw random numbers. Then sort the array on the second column and post the first column.
Edit:
As I read in the comments on the other answer, the purist solution would be to:
Assign each unique option of values a random value
Sort these random values either from top to bottom or bottom to top, and select the top one.
Place it in the first row
Do the same thing again for the second row, but keep track of the sum of all the unique options, as to rule out an option once it maxed its presence.
Edit2:
Once I just clicked post I thought this a bit more through and came to the conclusion that the last digit will allmost always be 1 in this case....

Need a simple search function to display most common value in a column. (with ambiguous choices)

I have a very large array of data with many columns that display different outputs for the values presented. I would like to add a row above the data that will display the most common occurring value or word below.
Generally I would like to have each top of the column (right under the column label in row 1) have the most common value below. I will then use this value for various data analysis functions!
Is this possible, and if so, how? Preferably this will not require VBA, but simply a short code in the cell.
One caveat: The exact values may vary, so there is no set list where I can say "it will be one of these."
Any ideas appreciated!
Try a series of =COUNTIF(A:A,"VALUE TO SEARCH") functions if you want to stay away from VBA.
Otherwise, the best method would be to iterate through each column via VBA. With this method, you can even count the "varying" values and return the count and/or the value itself.
http://www.excel-easy.com/examples/most-frequently-occurring-word.html
This is a single formula you would write at the top of each column. Does not require VBA. You can replace the set range to an entire column, such as (A:A) instead of (A1:A7).
If you mean an array as in a data type, it could work differently but it depends what you're trying to do.
With data from A3 through A16, in A2 enter:
=INDEX($A$3:$A$16,MODE(MATCH($A$3:$A$16,$A$3:$A$16,0)))
This will work for text as well as numbers. Adjust this to match the column size.

Count unique string variants

There could be quite a simple solution to this, but I am trying to find the number of times a unique variant (i.e. non-duplicates) of a string appears in a column. However this string is only part of the text contained in a cell, and not the entire cell. To illustrate:
EuropeSpainMadrid
EuropeSpainBarcelona
AsiaChinaShanghai
AsiaJapanTokyo
EuropeEnglandLondon
EuropeSpainMadrid
I would like to find how many unique instances there are of a string that contains "EuropeSpain". So using this example, I would find that a variant of "EuropeSpain" appears only twice (given that the second instance of "EuropeSpainMadrid" is a duplicate).
A solution to this is to use pivots to summarise the data and remove duplicated; however given that my underlying dataset changes often this would require manual adjustments and corrections. I would therefore like to avoid adding any intermediate steps (i.e. PivotTables, other data sets etc) between my data and the counts.
UPDATE: I now understand to use wildcards to solve the first part of my question (counting the occurrences of "EuropeSpain"), however I am not yet clear on the second part of my question (how to find the number of unique occurrences).
Is there a formula or VBA code that could do this?
Using wildcards:
=COUNTIF(A1:A6,"="&"*"&C1&"*")
For without VBA but with some versatility, I suggest with Text in ColumnA (labelled), ColumnB labelled Flag and EuropeSpain in C1:
=FIND(C$1,A2)
in B2 copied down.
Then pivot A:B with Flag for FILTERS (and 1 selected), Text for ROWS and Count of Text for Sigma VALUES.
Apply Distinct Values if required (and available!), alternatively a formula of the kind:
=MATCH("Grand Total",E:E)-4
would count uniques.

Find which rows has longest Cell in a given column?

Currently I have a function in VBA that finds the longest cell length in a given column. it inserts a column next to whatever given column, inserts LEN(A1) (whatever the desired column address is) and fills that down, then It uses the MAX function to find the greatest value.
Until now that's been good enough but now the user wants to know which row that greatest value is on as well. is there a way to do that without sorting or filtering?
The function is run once by the user and loops across each column, and there are about 150000 rows, so it would take a while to filter / sort 15 times.
any suggestions appreciated
=match(max(column),column,0) will give you the row number where the max occurs.
You could then use
=index(othercolumn,match(max(column),column,0)) to get some other column value for that row
Assuming values in A2:A6
This will give you row number, relative to the data range
=MATCH(MAX(LEN(A2:A6));LEN(A2:A6);0)
This will give row number relative to the worksheet
=ROW(A2)-ROW($A$1)+MATCH(MAX(LEN(A2:A6));LEN(A2:A6);0)
And this will give you the value
=INDEX(A2:A6;MATCH(MAX(LEN(A2:A6));LEN(A2:A6);0))
All those are array formulas, you need Ctrl+Shift+Enter to enter them
thanks to everyone who posted, I also found this formula: =CELL("address",OFFSET(A1,MATCH(MAX(A1:A10),A1:A10,0)-1,0)) (assuming data is A1 - A10) which will give the cells actual address as well if anyone ever wants it. heres the site for that: https://support.microsoft.com/kb/139574

Excel - How do I find all relevant rows by typing unique invoice# listed Col A

I have a Worksheet with 10 columns and data range from A1:J55. Col A has the invoice # and rest of the columns have other demographic data. Goal is to type the invoice number on a cell and display all the rows matching the invoice number from col A.
Besides auto filter function, the only thing comes to my mind is VBA. Please advice what is the best way to get the data. Thanks for your help in advance.
Alright, I'm pretty proud of this one. Again avoiding VBA, this one uses the volatile formula OFFSET to keep moving its VLOOKUP search down the table until it's found all matches. Just make sure you paste enough rows of the formula that if there are many matches, there's room for all of them to appear. If you put a border around your match area then it would be clear if you ever ran out of room and needed to copy down the formula some more.
Again, in the main section, it's just a single formula (using index):
=IFERROR(INDEX($A$1:$J$200,$M3,MATCH(N$2,$A$1:$J$1,0)),"")
This gets to be so simple because the hard work of the lookup is done by an initial column which looks up the next row that matches the invoice number. It has the formula:
=IFERROR(MATCH($L$2,OFFSET($A$1:$A$200,M2,0),0)+M2," ")
Here is the working example that goes with those formulas:
Let me know if you need any further description of how it works, but it mostly uses the same rules as above so that it's robust in copying and moving around.
I've uploaded the Excel file so you can play with it, but everything you need to reproduce this feature should be in this solution.
Google Docs - Click link and hit Ctrl+S to download and open in Excel.
A popular solution to this problem is a simple VLookup. Lookup the invoice the user types in on the table A1:J55, and then return an adjascent column's data.
Here's an example of it working:
The formula in the highlighted cell is:
=VLOOKUP($L3,$A:$J,MATCH(N$2,$1:$1,0),FALSE)
What's nice about this formula is you only need to type it once and then you can copy it across and it'll automatically pick out the correct column of the table (that's the match part). The rest is very simple:
The first part says lookup value $L3 (the invoice number typed in),
The second part says look it up in range $A:$J (which is where your table is located). I've shown how you can select the entire columns $A:$J so that you can add and remove data without worrying about adjustin the range in your lookups. (Excel takes care of optimizing the formula so that unused cells aren't checked)
The third part picks the column from which the resulting data will be drawn once a matching row is found.
The FALSE part is an indication that the invoice number must match exactly (no approximate matching allowed)
The $ signs ensure that fixed ranges like the location of your source table ($A:$J) and your lookup value ($L3) don't get automatically changed as you copy the formula across for multiple columns.
The formula is pretty easy to adapt if you want to move around your table and the area where you do your lookup. Here's an example:
Bonus
If you want to add a little spiff, you can add a dropdown to the Invoice # field so that the user gets auto-completion and the option to browse existing values like so: