Home » excel » excel – Average Based on Column Headers between certain numbers

# excel – Average Based on Column Headers between certain numbers

Questions:

So this has been a challenging problem for me. I am trying to get Excel to do an average over a period of time based on what is in the column header.

This is where the (Result) should go.

And then here is my original data (Nut Cost)

So the intent is that I can take the average for Peanuts between 201604 and 201703 based on the header ‘201604-201703 Avg’.

My thought is to use something like this:

``````=averageifs('Nut Cost'!\$B\$2:\$P\$5,'Nut Cost'!\$A\$1:\$P\$1,left('Result'!B2,6):mid('Result'!B2,8,6),'Nut Cost'!\$A\$2:\$A\$5,'Result'!\$A2)
``````

My other thought is to use something like this:

``````=SUMIFS('Nut Cost'!\$B\$2:\$P\$5,'Nut Cost'!\$A\$1:\$P\$1,">="&LEFT('Result'!B2,6),'Nut Cost'!\$A\$1:\$P\$1,"<="&MID('Result'!B2,8,6),'Nut Cost'!\$A\$2:\$A\$5,'Result'!\$A2)
``````

which would be divided by a countif with similar style.

``````=AVERAGEIFS(INDEX('Nut Cost'!\$B\$2:\$P\$5,MATCH('Result'!\$A2,'Nut Cost'!\$A\$2:\$A\$5,0),0),'Nut Cost'!\$B\$1:\$P\$1,">=" & left('Result'!\$B\$1,6),'Nut Cost'!\$B\$1:\$P\$1,"<=" & mid('Result'!\$B\$1,8,6))