averageifs with dynamic criteria

arvan

New Member
Joined
Mar 15, 2016
Messages
2
Hi friends!

I have a car data spreadsheet taken from a car listing website with ~7000 row entries of various cars currently on the market and only 4 columns: Make/Model, Production year, Miles and Price

I want to create a fifth column (E), where for each row I will be calculating the average market price of that specific car (based on the prices on that list), following though all the below rules

1) Model: consider prices only from cars of the exact same Make/Model
2) Production Year: consider prices from cars that have a production year from -1 to +1 (i.e. if the specific car's production year is 2012, i want to consider prices from cars between 2011 and 2013)
3) Miles: consider prices from cars with a mileage from -15000 to +15000 (i.e. if the spefic car has a mileage of 42000, i want to consider prices from cars with mileage between 27000 and 57000)
4) Avoid doublecounts (see below the example from Cintroen C5, this is a doublecount in the list

I tried to fix this in a singly formula with averageifs, but I am not able to add a dynamically running range in the function's criteria (I don't want to hard code the ranges, only the thresholds -+1 and -+15000)

Any thoughts? I am attaching also a sample view of the spreadsheet

Thanks!!!!

Make/ModelPriceProduction yearMilesAve price based on Model-Year-Miles
Mercedes-Benz A 16089002009150000
Citroen C440002006149980
Mercedes-Benz ML 320259002008149800
Renault Laguna99992012149500
Renault Kangoo51502007149456
Mercedes-Benz CLK 200139902008149392
Seat Cordoba37002006149142
Volkswagen Golf89002006149000
Nissan Qashqai125002009149000
Citroen C5118002011149000
Citroen C5118002011149000
Bmw 525109502006149000
Volkswagen Polo105552012149000
Opel Zafira105002011149000

<tbody>
</tbody>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
this should work except for the double counting that needed to filtered out beforehand.
but with 7000+ rows that will take ages, may be someone can provide a VBA solution


Excel 2012
ABCDE
1Make/ModelPriceProduction yearMilesAve price based on Model-Year-Miles
2Mercedes-Benz A 1608900200915000015323
3Mercedes-Benz A 160400020061499806540
4Mercedes-Benz A 16025900200814980013288
5Mercedes-Benz A 1609999201214950010931
6Mercedes-Benz A 1605150200714945610370
7Mercedes-Benz A 16013990200814939213288
8Mercedes-Benz A 160370020061491426540
9Mercedes-Benz A 160890020061490006540
10Mercedes-Benz A 16012500200914900015323
11Mercedes-Benz A 16011800201114900010931
12Mercedes-Benz A 16011800201114900010931
13Mercedes-Benz A 1601095020061490006540
14Mercedes-Benz A 16010555201214900010931
15Mercedes-Benz A 16010500201114900010931
Sheet1
Cell Formulas
RangeFormula
E2{=AVERAGE(IF(($A$2:$A$15=A2)*(ABS($C$2:$C$15-C2)<=1)*(ABS($D$2:$D$15-D2)<=15000),$B$2:$B$15))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
Two questions.
1) How do you recognise a doublecount ? Is it because all details are identical, and the two entries are consecutive ?
What would happen if you had two entries where details were identical but non-consecutive ?

2) What results do you want to see, if the data looks like this . . .
VW Golf.............10000......2006......100000
VW Golf.............12000......2007......110000
VW Golf.............15000......2008........50000
VW Golf.............11000......2006......120000
VW Golf.............20000......2009........55000
VW Golf.............22000......2010........60000
VW Golf.............18000......2008........65000
 
Upvote 0
Hi Gerald Higgins,

1) It would be a doublecount if it had the exact same data across all columns

2) VW Golf.............10000......2006......100000........10000
VW Golf.............12000......2007......110000.........11000
VW Golf.............15000......2008........50000.........17666
VW Golf.............11000......2006......120000.........11500
VW Golf.............20000......2009........55000.......19000
VW Golf.............22000......2010........60000.......21000
VW Golf.............18000......2008........65000......17666

as you can see, I am not excluding the respective row

The doublecount is the only issue that I have now, AlanY's solution worked!

Thank you so much!!!
 
Upvote 0
one way to delete all the repeat data;

copy E2 all the way down, sort column E, copy F2 all the way down.
create filter on Row 1, select "Y" from the filter menu in F1, delete all rows with "Y".


Excel 2012
ABCDEF
1Make/ModelPriceProduction yearMiles
2Mercedes-Benz A 16089002009150000Mercedes-Benz A 160 2009 150000N
3Citroen C440002006149980Citroen C4 2006 149980N
4Mercedes-Benz ML 320259002008149800Mercedes-Benz ML 320 2008 149800N
5Renault Laguna99992012149500Renault Laguna 2012 149500N
6Renault Kangoo51502007149456Renault Kangoo 2007 149456N
7Mercedes-Benz CLK 200139902008149392Mercedes-Benz CLK 200 2008 149392N
8Seat Cordoba37002006149142Seat Cordoba 2006 149142N
9Volkswagen Golf89002006149000Volkswagen Golf 2006 149000N
10Nissan Qashqai125002009149000Nissan Qashqai 2009 149000N
11Citroen C5118002011149000Citroen C5 2011 149000Y
12Citroen C5118002011149000Citroen C5 2011 149000N
13Bmw 525109502006149000Bmw 525 2006 149000N
14Volkswagen Polo105552012149000Volkswagen Polo 2012 149000N
15Opel Zafira105002011149000Opel Zafira 2011 149000N
Sheet1
Cell Formulas
RangeFormula
E2=A2&" "&C2&" "&D2
F2=IF(E2=E3,"Y","N")
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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