简体   繁体   中英

Calculate a dynamic average from a table in excel

I have this table of currency rates: 在此处输入图片说明

I would like to create a formula that receives the begin date and end date + currency, and in return will calculate the average for every month inside the range.

For example, if the currency is GBP, begin date is 15/09/2015 and end date is 20/11/2015, I would like to calculate averages for 30/09/2015 + 31/10/2015 + 30/11/2015.

I tried to solve it with a simple Average + Vlookup + Match functions, but it wouldn't get me the range of cells but only the edges of the range. I also thought of using AverageIF function, but I'm not sure how to combine between the criterias of date and currency.

Can you think of an easy way to solve that?

I suggest using an index/match to get a reference to the beginning of the range of currencies then another one to get the end of the range and combining them like this:-

=AVERAGE(INDEX($B$2:$H$10,MATCH(D13,A$2:A$10,0),MATCH(1,(MONTH(E13)=MONTH($B$1:$H$1))*(YEAR(E13)=YEAR($B$1:$H$1)),0)):
INDEX($B$2:$H$10,MATCH(D13,A$2:A$10,0),MATCH(1,(MONTH(F13)=MONTH($B$1:$H$1))*(YEAR(F13)=YEAR($B$1:$H$1)),0))
)

Where the currency name is in D13, start date in E13 and end date in F13, and the table is in A1:H10.

Result: 1.5203

Must be entered as an array formula using Ctrl Shift Enter

Found a way to solve this, by using the AVERAGEIF function. Enjoy, and thanks for helping!

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM