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

# excel – Average Based on Column Headers between certain numbers

Posted by: admin May 14, 2020 Leave a comment

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.

So here’s the column header that I’m talking about: 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.

How to&Answers:

Use INDEX to return the correct row to the AVERAGEIFS()

``````=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))
`````` 