Search code examples
excelexcel-formulasumifs

SUMIF formula to find sum for dates today or earlier


so I have this table of salaries that I make (hypothetically):

       A           B            C         D
1                  Date         salary    how_much_I_earned_so_far
2      total                              =SUM(salaries_until_today)
3                  2017-10-1    5000            
4                  2017-11-1    5000
5      today->     2017-12-1    5000    
6                  2018-01-1    5000
7                  2018-02-1    5000
8      future..    2018-03-1    5000
9                  2018-04-1    5000

now I want to calculate on D2 the amount of money I have earned so far.. to do that, I want to sum up all the past salaries from C3 all the way down to C_x where x is the index of the line where today < B_x

so that raised me two questions

1) how do I select unknown index of cell? usually when I do formulas it looks like this =SUM(C2:C9) so how can I make the number 9 be variable?

2) can I create variable that depends on a number of lines of where a cell is smaller than a value? I know how to get the current day, its simply =TODAY() but now I want to compare it with all B's and find the index of line where its smaller than it.. how do I start?

I'm sorry if that's a weird question, I'm a programmer and its frustrating me that a simple thing that I could quickly solve by code cannot be accomplished in a sophisticated app such excel..

thanks.


Solution

  • =SUMIF(B:B,"<=" & TODAY(),C:C)