[英]Excel: Calculate number of months in date range, but only for specific year
My sheet looks like this (sample data)我的工作表看起来像这样(示例数据)
"Rate" "Begin" "End" “速率”“开始”“结束”
"1$" "01.01.2011" "01.01.2015" "1$" "01.01.2011" "01.01.2015"
"2$" "01.06.2012" "01.08.2013" "2$" "01.06.2012" "01.08.2013"
I want to calculate the number of months for the date ranges which fall in specific years (2012, 2013, 2014) to estimate volume (= months*rate) For example in the 2nd line I would get 6 months for 2012 (=12$) and 7 months for 2013 (=14$).我想计算属于特定年份(2012、2013、2014)的日期范围的月数以估计数量(= 月*率)例如在第二行中,我将获得 2012 年的 6 个月(=12$ ) 和 2013 年的 7 个月 (=14$)。 How can I achieve this?
我怎样才能做到这一点?
Assuming you have your data in A1:C3 then list the years in the header row, eg D1 = 2012, E1 = 2013, F1 = 2014 then in D2 use this formula:假设您在 A1:C3 中有数据,然后在标题行中列出年份,例如 D1 = 2012、E1 = 2013、F1 = 2014 然后在 D2 中使用以下公式:
=IFERROR(DATEDIF(MAX($B2,DATE(D$1,1,1)),MIN($C2,DATE(D$1+1,1,1)),"m"),0)*$A2
format as currency and copy across and down格式为货币并上下复制
Assumes you are using Excel 2007 or later and that columns B and C contain valid dates.假设您使用的是 Excel 2007 或更高版本,并且 B 列和 C 列包含有效日期。 In earlier Excel versions you can use this alternative formula
在早期的 Excel 版本中,您可以使用此替代公式
=LOOKUP(99^99,IF({1,0},0,DATEDIF(MAX($B2,DATE(D$1,1,1)),MIN($C2,DATE(D$1+1,1,1)),"m")*$A2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.