There are two tables, each with a coordinate pair: longitude and latitude, in decimal degrees (i.e. 37.23222, -121,3433). How do I match table A with its nearest coordinate pair in table B?
You could try filling down this formula from G1 as shown below:
=LOOKUP(1,1/FREQUENCY(0,MMULT((B$1:C$10-E1:F1)^2,{1;1})),A$1:A$10)
For a more accurate formula that takes account of the circular distances try filling down from H1:
=LOOKUP(1,1/FREQUENCY(0,SIN((RADIANS(B$1:B$10-E1))/2)^2+SIN((RADIANS(C$1:C$10-F1))/2)^2*COS(RADIANS(B$1:B$10))*COS(RADIANS(E1))),A$1:A$10)
This problem was solved back in 2006 by Tom Ogilvy here, also found here.
The sample that I created:
Original problem:
I have 20 named locations in a coordinates. Every point have x,y.
column a has the location name
column b has the x cooedinate
column c has the y coordinate
Now i have 400 coordinates in 2 columns (column e and f ) and want to
have the name of the closest location (of the 20 named in column a) in column g.
Original solution by Tom Ogilvy:
Assuming original data starts in A1, B1 and C1 with first locations in E1
and F1
If you don't want to fill your sheet with formulas, you can put this in G1
committed/entered with Ctrl+Shift+Enter rather than just enter since it is
an array formula, then drag fill it down the 400 rows.
=INDEX($A$1:$A$20,MATCH(MIN(SQRT(($B$1:$B$20-E1)^2+($C$1:$C$20-F1)^2)),SQRT(
($B$1:$B$20-E1)^2+($C$1:$C$20-F1)^2),0),1)
Related
Imagine you have spreadsheet with data in a fixed # of contiguous rows.. let's say row 1 through row 20
Now let's say you have 3 columns of interest.
A, B and C
Column A is a label column.. the data in there are just string labels.. let's say types of canned food.. Tuna, Spam, Sardines, etc.
Column B is our number column.. let's say it is prices. e.g. 2 for Tuna, 5 for Spam and 3 for Sardines. These prices can change often very rapidly.. ok so prices are not the best example but let's imagine that prices change rapidly.
Now Column C is where we want to put the formula.
I would like to have a formula in Column C that will pull the labels from Column A, based on their prices in column B and rank them from highest to lowest.. that is C1 would calculate to "Spam", C2 to "Sardines" and C3 to "Tuna"
right now there are 20 rows of data.. but maybe at some other point there might be 30 or 6 or 40, etc.
So can someone help me out with the formula or at least explain what functions I need to use and the general idea involved? thanks
=IF(A2:A200<>"";SORTBY(A2:A200;B2:B200;-1);"")
You can simply use SORT formula. In this case =SORT(A1:B1000,2,-1) where A1:B1000 is range to be sorted, second parameter 2 is column number from range to sort by, 3rd parameter for order (-1 is desceding).
Place formula in C1 and you will get spilled array.
I have a table in a tab with columns: street_id, street_name, street_corner_1 and street_corner_2 (a street corner is the name of the street that intersects it at the beginning or end).
So I have in another tab a table where columns go through street1 to streetn, rows work the same (like a matrix), and I want to check if the name of the street of row 1 (street1) is either the street corner 1 or 2 of street2.
What I wanted to do is format the cell so =COUNTIF(VLOOKUP(street2;street_id:street_corner_2;{3;4}),VLOOKUP(street1;street_id:street_name;2))>0
So, the range for the countif would be the two street corners of street2 and the criteria would be the name of street1, and the cell would be 1 if the name of street1 is among the corners of street2 and 0 otherwise.
I want to define the range with VLOOKUP, how can I do this?
I made a fake dataser including a street map to see if this what you mean. You want a matrix table with the first and last intersection and check if it's corner 1, corner 2 or nothing.
You can do it with 2 VLOOKUPS. My formula is (note I'm using mixed references so I can use same formula for all columns and rows):
=IF(I$1=$H2;"-";IF(VLOOKUP(I$1;$A$2:$D$5;3;FALSO)=$H2;"Corner 1";IF(VLOOKUP(I$1;$A$2:$D$5;4;FALSO)=$H2;"Corner 2";"-")))
Click HERE for excel file.
In the Excel file based on Column B values I am finding nearest up offer price range which is in Row number 2 in Grey Color, Offer price per sqm is incremental by $50. As you can see in Yellow color values are multiplied by offer price * Land sqm.
3rd property nearest offer price range is $750. As you can see I am using multiple columns from C, D, E, F.
Instead what I want is get the "Offer Price per/sqm" value in column "G". How to do that.?
Though you are not pretty clear about the output you want, I think you want to round the offer price to nearest 50. If so, use this in G3 (and copy down)
=MROUND(A3/B3, 50)
this will return $700 as nearest offer price. However, if you want to round only upwards i.e. towards $750, use this (and copy down)
=CEILING(A3/B3, 50)
If you want either of these formulae to return values between 650 and 800 only use either of these
=IF(AND(CEILING(A3/B3, 50)>=650, CEILING(A3/B3, 50) <=800), CEILING(A3/B3, 50), "NA")
Based on your comment, perhaps you need this?
=IF(AND(CEILING(A3/B3, 50)>=650, CEILING(A3/B3, 50) <=800), CEILING(A3/B3, 50)*B3, "NA")
I wonder if this is what you want.
[G3] =B3*INDEX($C$2:$F$2,1,MATCH("x",C3:F3,0))
You would mark the appropriate column with an "x" and the formula would multiply the price in row 2 of the first marked column with the number of sqm.
To simulate your example, an "x" would be placed inE3 and F3. The formula in G3 would ignore the F3 and show the price based on E2. If you add an "x" in D3 the lower price will be shown in G3.
Column A Has Text & Columns B, C & D contain numbers.
For Ex.)
A... …B C D
John 4 6 2
Dave 4 6 4
Mike 4 5 1
Bill 2 5 9
I would like a cell to return the name in column A that has the Largest Number in Column B. And if there are similar numbers, go to the next column and determine which is highest, and if that is tied go to the next column and so on.
Any help would be appreciated.
We can de-conflict ties.In E1 enter:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))
and copy down. Then in another cell enter:
=INDEX(A:A,MATCH(MAX(E:E),E:E,0))
EDIT#1
This is only good for 3 columns of numbers, but it is very easy to add additional de-confliction terms if necessary:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))+E1/(1000*MAX(E:E))
For an expandable number of rows/columns, use a helper row with the same number of columns as number columns in your data. The formulas below reference the following image (the data are in A1:G7):
B9-->=MAX(B1:B7)
C9 (fill over the remaining columns to G9)-->
=MAX(IF(MMULT(--($B1:B7=$B9:B9),--(ROW(INDIRECT("1:"&COLUMNS($B9:B9)))>0))=COLUMNS($B9:B9),C1:C7))
The following formula will give the answer (shown in A9 above):
=INDEX(A1:A7,MATCH(TRUE,(MMULT(--($B1:G7=$B9:G9),--(ROW(INDIRECT("1:"&COLUMNS($B9:G9)))>0))=COLUMNS($B9:G9)),0))
UPDATE WITH ALTERNATIVE METHOD
Using a helper column instead, again referencing the image below (the data are in A1:G7):
I1 (fill down to I7)-->
=SUM(--(MMULT(SIGN(B1:G1-$B$1:$G$7)*2^(COLUMN(G1)-COLUMN(A1:F1)),--(ROW(INDIRECT("1:"&COLUMNS(B1:G1)))>0))>0))
The following formula will give the answer (shown in J1 above):
=INDEX(A1:A7,MATCH(MAX(I1:I7),I1:I7,))
As a bonus, notice that the helper column corresponds to the order that you would get from sorting the data by each column left-to-right. In other words, you could use the helper column to perform a formula-based multi-column sort on strictly numeric data. For the last image, entering the following array formula into a range with the same dimensions as A1:G7 gives a descending sort on columns B through G:
=IF(A1:A7=A1:A7,INDEX(A1:G7,MATCH(ROW(A7)-ROW(A1:A7),I1:I7,0),))
I have a spreadsheet with different products, listing units and retail value sold like the example below
Product Units Value
A 10 100
B 15 80
C 30 560
I'd like to compare the Average Selling Price with the Median Selling price, so I am looking for a quick formula to accurately calculate the median.
The median function requires the entire series, so for Product A above I would need 10 instances of 10 etc. How can I calculate the Median quickly considering the condensed form of my data?
Without writing your own VBA function to do this there are a couple of approaches that can be taken.
The first expands the data from its compressed frequency count format to generate the full set of observations. This can be done manually or formulaically. On the assumption the latter is required, it can be achieved using a few columns.
All the blue cells are formulae.
Column Eis simply the cumulative of column B and F is an adjusted version of this. Column H is just the values 1 to 55, the total number of observations given by cell L2. Column I uses the MATCH() with its final argument as 1 to match each observation in H against the adjusted cumulative in F. Column J uses the INDEX() function to generate the value of the observation. (Observations 1-10 have value 100, 11-25 have value 80 and 26-55 have value 560 in this example). The MEDIAN() function is used in cell M2 with column J as its argument.
This approach can be refined to take account of varying numbers of products and data points through the use of the OFFSET function to control the range arguments of the MATCH(), INDEX() and MEDIAN functions. And, of course, adjacent cells in columns I and J could be combined using a single formula - I've shown them separately for ease of explanation.
The second approach involves sorting the data by value (so in this case the data rows would become Product B in row 2, product A in row 3 and product C left as-is in row 4). It is then a case of identifying the middle observation number (if the number of observations is odd) or the middle pair of observation numbers (if the number of observations is even) and then determining the value(s) corresponding to this/these middle observation(s). In this approach the adjusted cumulative in column F is still used but rather than explicitly calculating the values in column I and J for every observation it can now be restricted to just the middle observation(s).
I think there is no way around compromises. Either using big amounts of helper cells or having the table sorted by the values.
Helper cells:
Formula in F4:AS6:
=IF(COLUMN()<COLUMN($F$4)+$B4,$C4,"end")
Formula in D2:
=MEDIAN(F4:AS6)
Sorted:
Formula in F4 downwards:
=SUM($B$3:B3)+1
Formula in D2:
=SUM(LOOKUP(INT(SUM(B4:B6)/2+{0.5,1}),F4:F6,C4:C6))/2