Index Match for closest value with multiple conditions

abschy

New Member
Joined
Mar 20, 2019
Messages
29
Hi all,

I'm having issues coming up with a formula that gives an approximate match value based on multiple conditions..

My data:
- Column A = Region
- Column D = Brand
- Column F = Size
- Column J = Cost psm

So far, i have this formula that works to give the average cost psm of a project in a certain region.
- B4 contains the region, C7 contains the brand i want and C8 contains the size i want to estimate for

=IFERROR(ROUNDUP(SUMIFS(Table3[COST PSM],Table3[Region],'Formula Testing'!$B$4,Table3[Brand],'Formula Testing'!C$7,Table3[COST PSM],">0")/COUNTIFS(Table3[Region],'Formula Testing'!$B$4,Table3[Brand],'Formula Testing'!C$7,Table3[COST PSM],">0")*'Formula Testing'!C$8,-2),"")

I now need to improve the formula to give me an approximate average cost psm of a certain project in a certain region based on size.

For example,
Brand A in SEA has 10 projects, all with differing sizes - eg 0.2 sqm to 50 sqm, and if i want the average cost psm of a size 7 sqm, in the above equation, i would like for the SUMIFs portion of the equation to return the sum of costs for projects which are the closest to 7sqm.

1583219544195.png
So in this example, i only want the average cost psm of the 2 red numbers.


Would this be possible?

Any help is appreciated!

Thank you!!

Best,
Abigail
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this...

This assumes that there will be enough data to bound the target size, otherwise the 2-point linear interpolation for cost estimation will fail.

Book1
ABCDEFGH
1Fill yellow cells with desired parametersBrandRegionSize/sqmCost PSM
2AChina405.00
3AChina314.00
4Region -->ChinaASEA430.00
5ASEA524.00
6ASEA920.00
7Brand -->CBChina132.00
8Size -->15.5BSEA196.00
9CChina292.00
10Cost InterpolationCChina0.851.00
11SizeCost
12largest below0.851
13smallest above292
1415.525.45745<-- est. based on linear interpolation
Sheet7
Cell Formulas
RangeFormula
B12B12=MAX(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)<=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)))
C12C12=MAX(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)<=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($H$2:$H$10)))
B13B13=MIN(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)>=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)))
C13C13=MIN(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)>=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($H$2:$H$10)))
B14B14=C8
C14C14=FORECAST(B14,C12:C13,B12:B13)
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Sorry, but I discovered an error where C12:C13 weren't returning the correct value. I've incorporated a work-around in this solution and added some improvements and messaging to the final cost interpolation formula to cover cases where the target combination is represented exactly in the table and where there is only one data point.

Book1
ABCDEFGH
1Fill yellow cells with desired parametersBrandRegionSize/sqmCost PSM
2AChina405.00
3AChina314.00
4Region -->ChinaASEA430.00
5ASEA524.00
6ASEA920.00
7Brand -->ABChina132.00
8Size -->30BSEA196.00
9CChina292.00
10Cost InterpolationCChina0.851.00
11Size/sqmCost PSM
12largest size below00.00
13smallest size above314.00
1430only 1 pt<-- est. based on linear interpolation
Sheet7
Cell Formulas
RangeFormula
B12B12=MAX(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)<=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)))
C12:C13C12=SUMPRODUCT(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10=B12)*($H$2:$H$10))
B13B13=MIN(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)>=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)))
B14B14=C8
C14C14=IF(B14=B13,C13,IF(OR(B12=0,B13=0),"only 1 pt",FORECAST(B14,C12:C13,B12:B13)))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
I'll try once again...I discovered an issue with the last improved version when/if there are duplicates in the data table. Cells C12:C13 would still return an incorrect answer if the duplicates were involved in the cost calculation. Please disregard the earlier versions and consider this one. Also note in the cell formula section that the array formulas found in B12, B13, C12, and C13 will need special treatment...click on each, hit F2, then CTRL-SHIFT-ENTER

MrExcel_2.xlsm
ABCDEFGH
1Fill yellow cells with desired parametersBrandRegionSize/sqmCost PSM
2AChina405.00
3AChina314.00
4Region -->SEAASEA430.00
5ASEA524.00
6ASEA920.00
7Brand -->ABChina132.00
8Size -->12.5BSEA196.00
9CChina292.00
10Cost InterpolationCChina0.851.00
11Size/sqmCost PSM
12largest size below920.00
13smallest size above524.00
1412.518.70<-- est. based on linear interpolation
15
Sheet7
Cell Formulas
RangeFormula
B12B12=MAX(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)<=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)))
C12:C13C12=MAX(--($E$2:$E$10=$C$7)*--($F$2:$F$10=$B$4)*--($G$2:$G$10=B12)*($H$2:$H$10))
B13B13=MIN(IF(($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)>=$C$8,($E$2:$E$10=$C$7)*($F$2:$F$10=$B$4)*($G$2:$G$10)))
B14B14=C8
C14C14=IF(B14=B13,C13,IF(OR(B12=0,B13=0),"only 1 pt",FORECAST(B14,C12:C13,B12:B13)))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top