In excel it helps to slip your formula into separate chunks. So in one column you print which percentile the values are in. Then you use that as input for the next. That way you can see what the intermediate values are.
For this you could actually use AVERAGEIF. This average you can give a condition that the percentile should be between 25 and 75.