I don't like that the rule you use to describe your change is just a list of examples that the actual rule has to be deduced from.
Here is what I think you want it to do:
New Price is:
IF the month of the record is less than the "Period"
TRUE: Market Price
FALSE: The average of all months less than the "Period" (assumed: in the same year).
Anyway try this in C5 and pull down:
=IF(MONTH(A6)<Period, B6, SUMPRODUCT(Market_Price,--(MONTH(dates)<Period),--(YEAR(dates)=YEAR(A6))) / SUMPRODUCT(--(MONTH(dates)<Period),--(YEAR(dates)=YEAR(A6))))
I wanted to use AVERAGEIFS, but since you needed to operate on the "dates" range, that wasn't feasible.
Bookmarks