"main" is a worksheet with a "Week ending" column in it. "expenses" is a worksheet with expense figure in column B and specific dates in column A.
I want to sum the expenses that occur on or up to 7 days before the main Week ending date.
Following the examples here: https://www.ablebits.com/office-addins-blog/2014/11/04/excel-sumif-function-formula-examples/
I came up with this
=SUMIF(expenses!A2:expenses!A1024,main!$A$2&"<="&expenses!$A$2,expenses!B2:expenses!B1024)
But it gives me zero.
EDIT
The worksheets look like this:
Main
|A |B |C |D |E |F |
|Week Ending| | | | |Expenses |
|16/11/2014 | | | | |formula goes here = should total 100|
|23/11/2014 | | | | |formula goes here = should total 25|
Expenses
|A |B |
|Date |Value|
|10/11/2014 |5.00|
|11/11/2014 |20.00|
|12/11/2014 |15.00|
|12/11/2014 |10.00|
|10/11/2014 |50.00|
|17/11/2014 |5.00|
|18/11/2014 |20.00|
This works if I just put the week ending date in the expenses sheet:
=SUMIF(expenses!A2:expenses!A1024, main!a2, expenses!b2:expenses!b1024)
But I can't change the dates because they have to match the receipts. So I tried using AND:
=SUMIF(expenses!A2:A1024, AND("<="&main!A2, ">"&main!A2-7), expenses!A2:expenses!A1024)
Still zero.
@pnuts
I tried your SUMIFS suggestion but I still get zero.
expenses!A2:expenses!A1024
should be actuallyexpenses!A2:A1024
(sheet name is mentioned once for any range). Secondly, you don't need to mention the cell reference A2 in the condition, so try:=SUMIF(expenses!A2:A1024,"<="&main!$A$2,expenses!B2:B1024)
(please type it all, and don't copy from here because the formula breaks on two lines and this will cause errors). GSpreadsheet example. – Jerry