I'm trying to create a moving average of the last work day of each week. So is there a formula that I can change how many values that it will average backwards even if there are blank spaces and some work weeks are longer than others? For example say I decided to average the last 4 ending work days and the search range could be something like I395 back to I355 but the formula in cell K395 would return the answer of: 125.25 (the average of 125, 126, 124, and 126) since these are the last 4 values going backwards starting at cell I395. This answer would be the same all they way up to K391. If the formula was entered in K390 if would recalculate a different answer.

Of course some weeks have fewer work days because of holidays so if I were to use a simple average formula it would throw the accuracy off for long calculations and day to day calculations.

So the formula in just simplified words would be something like this: In the range of I395:I355, Average the last 4 visible values starting at cell I395

Is there a formula that can do this? Any help would be very appreciated.

I used the "=IF(AND" formula for column I and column J.