Sum of values for a given week - excel

I have a sheet that is tracking the cost of transactions ordered by date. This is how it looks so far:
I would now like to add another column that has the Weekly Totals (Monday - Sunday) printed in the last row for each Sunday. How can this be done?
I have tried this formula so far:
=IF(AND(WEEKDAY(A2)=0,A2<>A3),SUMIF(A:A,AND(<=A1>=A1-6),B:B))
but it is the use of two criteria in the SUMIF that has me lost.

I think the following formula is what you need:
=IF(AND(WEEKDAY(A2)=1,A2<>A3),SUMIFS(B:B,A:A,">="&(A2-6),A:A,"<="&A2),"")
Note that the SUMIFS function is used to handle the multiple IFs, as opposed to the SUMIF function.
The IF function uses the AND function to test two conditions:
Is the WEEKDAY number equal to 1? (e.g., is this row for a Sunday?)
And is the current row's date non-equal to the next row's date? (e.g., is this the last row for the date?)
If either of the above are false, then the formula returns an empty string, "". If both of the above are true, then it sums the values in column B if the following two conditions are both met:
The value in column A is greater than or equal to the value of the current date minus 6 days.
The value in column A is less than or equal to the value of the current date.

Related

row number of First cell in a column with specific condition

The cells in column A are Date type.
How can I get the row number corresponding to the first cell whose month is equal to a certain number?
Try MATCH() function.
=MATCH(9,MONTH(A1:A12),0)
If you date stars from few row below then try
=MATCH(9,MONTH(A8:A19),0)+ROW($A$7)

On Excel is it possible to apply a certain formula after a new date is written on another cell?

I would like to apply this formula =SUMIFS(K:K;A:A;A3) on a cell on a column only after a change in the date for example:
On this image the 14/12 a sum is calculated 2 times while I would love it if only on sum would calculate for each day. Is this possible maybe add a check weather whats MAX day?
Use =IF(COUNTIF(A$1:A3;A3)-COUNTIF(A:A;A3)=0;SUMIFS(K:K;A:A;A3);"") in the same row # as A3
The 1st countif is a counter from the first row up to the current row meeting the condition.
The 2nd countif is a counter of total occurances of the condition.
If 1st minus 2nd equals 0 it'll show your sumif formula, else it shows blank.

Find Last Entry in Row, then Return Value of Cell in Top Row of That Column

I have a spreadsheet that records how many times different people have been to an event, names vertically, dates horizontally, with a 1 in each cell to denote attendance, so that the total can be summed up.
What I want is to automate the process of working out who hasn't attended in a long time, so that it will lookup the right-most (most recent) entry in a row, and return the value of the date, which will be in row 1 of that column, so I can create a column of last attended date to sort data by.
I can't work out how to assemble the formula for this, what would be the best way to do it?
Many thanks for any ideas!
You could use an array formula:
{=MAX((B2:D2)*$B$1:$D$1)}
This formula would be the one to use for the 2nd row, assuming that the 1st row contains your dates and that dates range from column B-D.
Using the array formula carries out a vector multiplication (item by item) so in case there is a 1 (marking attendance) the date will be considered in the MAX formula an in case the cell is empty it will be effectively a zero. Therefore the MAX is only applied to dates where there is an attendance and the result will be the latest attendance date.
For an array formula to work you will need to use Ctrl+Shift+Enter after entering it into the cell. The brackets {} will then be added automatically. You do not type these yourself.

Excel Formula for averaging by weekday

I'm trying to summarize 2 years worth of data quickly by month. What I want to do is to average only the values from Monday to Friday for each month.
If you change column b to be a calculated day of week field like so:
=TEXT(B2, "ddd")
And you insert a new column c field that is calculated month like so:
=TEXT(B2, "mmm")
You can then use an array formula to solve your problem. You might need to modify the formula slight based upon your data but the follow formula should work.
=AVERAGE(IF((C:C<>"Sat")*(C:C<>"Sun")*(D:D="May"),E:E))
Keep in mind because this is an array formula you have to hit Ctrl+Shirt+Enter on a PC or Command+Return on a Mac. Basically what it is saying is that if column C is not Sat and not Sun and column D is May, then average the value in column E.
Not too difficult.
Try this:
= SUMPRODUCT((WEEKDAY(B2:B99,2)<6)+0,D2:D99)/SUMPRODUCT((WEEKDAY(B2:B99,2)<6)+0)
I have the last row as 99 but you can just change that 99 to whatever your last row is that you need.
EDIT:
Just noticed you said "by month". The formula above will take the average column D where column B is a weekday. To modify for a specific month, the formula just needs to be slightly modified to account for the month also. See below, this shows how to do it for the month of May. (Month = 5) I broke it up into two lines so it is easier to read.
= SUMPRODUCT((WEEKDAY(B2:B99,2)<6)+0,(MONTH(B2:B99)=5)+0,D2:D99)
/SUMPRODUCT((WEEKDAY(B2:B99,2)<6)+0,(MONTH(B2:B99)=5)+0)
Similar to peter's answer, use the following formula in K2:
=SUMPRODUCT((WEEKDAY(B:B,1)>1)*(WEEKDAY(B:B)<7)*(MONTH(B:B)=MONTH(DATEVALUE("01-"&$J$2&"-2017")))*(D:D))/SUMPRODUCT((WEEKDAY(B:B,1)>1)*(WEEKDAY(B:B)<7)*(MONTH(B:B)=MONTH(DATEVALUE("01-"&$J$2&"-2017"))))
Warnings: Despite not being a CSE /ARRAY formula, SUMPRODUCT performs array like calculations within its brackets. As such, full column references like B:B should not be used. Instead B:B should be adjusted to match the needs of your data. In this case it should be B2:B22.
In the sumproduct formula above, the * are acting like AND statements. It evaluates a logical comparison to either true or false. If true or false is then put through a math operation, true values become 1 and false values become 0. Therefore only rows where everything is true are counted. The last step of the sumproduct is to sum all the results. Therefore all rows containing a false will become zero and not affect the summation.
The tid bit in the formula that refers to J2 basically converts what is assumed to be a month in text to a date that can be recognized by excel which then converts it to a numeric value which can then be compared to the month in your date list. Now the only caveat here is that its every month of year irregardless of the year. If you need a month from a specific year you will need the formula adjusted.

Use ADDRESS function to define range in MIN

I'm a newby to this forum. I have a spreadsheet which predicts bank balance based on future events. I want to know the minimum balance in the future, to ensure I don't overspend.
I can find the minimum in the account over whole range of dates by using MIN, but this includes past dates. I want to vary the range in the MIN argument based on the TODAY function.
I can return the cell reference I need to use for today's date using =ADDRESS(MATCH(DATEVALUE(TEXT(TODAY(),"dd mmm yy")),C:C,0),COLUMN(E2),4), where Column C contains dates, and Column E the bank balance. However, I cannot then use the value of the cell in the MIN formula.
So, at present, MIN(E10-E121) works for past and future levels, but if the ADDRESS routine for todays date returns E90 in cell A1, I cannot reference A1 within the MIN function to get the range E90:E121.
I have tried INDIRECT, but this gives the value of the cell at E90.
Assuming your data is in rows 2 to 100, this will give you the smallest amount anywhere in column E where the date in column C is today or later. It's an array formula, so must be entered with Ctrl-Shift-Enter:
=MIN(IF(C2:C100>=TODAY(),E2:E100))
EDIT:
In response to your comment about how to do it using one cell in a range, this uses Match to find the last cell in column C that is less than or equal to Today() and then uses that as the Index into the first half of a range specification in column E. It requires the column be sorted, ascending, by date, and if today isn't in column C it will start with the highest row in column C with a date before today. You could fiddle with the last argument in Match - 1, 0, or -1, but if C always contains today's date this will work:
=MIN(INDEX(E2:E100,MATCH(TODAY(),C2:C100,1)):E100)
Another solution that does not involve array formulas (but with a little more involved formula):
=SUMPRODUCT(MIN((C2:C100<TODAY())*(1+MAX(E2:E100))+(E2:E100)*(C2:C100>=TODAY())))

Resources