如何总结一个时间间隔

我正在寻找一个公式或macros,可以采用以下几点:我需要总结每周的金额。 这应该从一开始就完成。 我的数据结构如下:

Col A Col B Column C Year Week Amount 2000 1 368 2000 2 8646 … … … 2000 52 46846 2001 1 656 2001 2 846 … … … 2001 52 4651 2002 1 489 … … … 2014 52 46546 

我会有一个列D,其中我有每周金额的平方和。 所以Cell(“D”列,“2000w1周”)应该是,

 =SUMSQ(Amount 2000w1) 

第一年,这很容易。 问题出现在明年。 在细胞中(“D”列,“2001w1”周)

 =SUMSQ(Amount 2000w1;Amount 2001w1) 

在去年,细胞(“D”列,“2014w1”周)应该是公式,

 =SUMSQ(Amount 2000w1;Amount 2001w1; Amount 2002w1;Amount 2003w1;Amount 2004w1; Amount 2005w1;Amount 2006w1;Amount 2007w1; Amount 2008w1;Amount 2009w1;Amount 2010w1; Amount 2011w1;Amount 2012w1;Amount 2013w1) 

这一年应该做1到52周。 有没有一个快速的方法来做到这一点?

这是一个带有工作表function的解决scheme,你也可以用macros来开发类似的工具,但是我认为现在没有它,

=SUMSQ(INDEX([Amount]*([Week]=[@Week])*([Year]<=[@Year]),0))

在这里输入图像说明

谢谢JuhászMáté偷窃我的垃圾。 现在我觉得有这个发展愚蠢。
无论如何,这是一个VBA解决scheme。
对于您的示例数据集=SUMQ($C:$C, $B:$B, $B2)将给出804,881即* 804,881 * s平方的总和。
高级用法=SUMQ($C:$C, $B:$B, $B2, $A:$A, "<=", $A2)将得到135,424 ,这是* 135,424 *大于等于2000

 Public Function SUMQ(NumsToSquare As Range, Filter1 As Range, FilterCriterion As Variant, _ Optional Filter2 As Range, Optional FilterRelation As String, Optional FilterCriterion2 As Variant) As Long Set NumsToSquare = Intersect(NumsToSquare, NumsToSquare.Worksheet.UsedRange) Set Filter1 = Intersect(Filter1, Filter1.Worksheet.UsedRange) RowsCount = Filter1.Rows.Count ColumnsCount = Filter1.Columns.Count If Not Filter2 Is Nothing Then Advanced = True If Advanced Then Set Filter2 = Intersect(Filter2, Filter2.Worksheet.UsedRange) On Error Resume Next For i = 1 To RowsCount For j = 1 To ColumnsCount If Not Advanced Then If Filter1(i, j).Value2 = FilterCriterion Then SUMQ = SUMQ + NumsToSquare(i, j).Value2 ^ 2 Else If Filter1(i, j).Value2 = FilterCriterion And Judge(Filter2(i, j).Value2, FilterRelation, FilterCriterion2) Then SUMQ = SUMQ + NumsToSquare(i, j).Value2 ^ 2 End If Next j Next i End Function Private Function Judge(var1 As Variant, FilterRelation As String, var2 As Variant) As Boolean Judge = False On Error GoTo err: Select Case FilterRelation 'cf. https://msdn.microsoft.com/en-us/library/aa711633(v=vs.71).aspx Case "=" 'The = operator tests whether the two operands are equal. Judge = (var1 = var2) Case "<>" 'The <> operator tests whether the two operands are not equal. Judge = (var1 <> var2) Case "<" 'The < operator tests whether the first operand is less than the second operand. Judge = (var1 < var2) Case ">" 'The > operator tests whether the first operand is greater than the second operand. Judge = (var1 > var2) Case "<=" 'The <= operator tests whether the first operand is less than or equal to the second operand. Judge = (var1 <= var2) Case ">=" 'The >= operator tests whether the first operand is greater than or equal to the second operand. Judge = (var1 >= var2) End Select err: End Function