Excel Formula for averaging by weekday - excel

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.

Related

Average of sum of column values

I have a table with 2 columns : dates (1st of the month) and values. Each date can appear an unknown number of time. I am trying to find a formula that would make a yearly average of the sum of the value for each month.
I can easily make several sumproducts to have the sum of values for each month and then average but I would prefer to limit the size of the formula.
Does anyone has an idea on how to do that, or if that's even possible?
I assume that dates are in A column and values in B column.
The easiest way would be:
1) In third column (C), store the integers indicating the month. You will get this result by simple =MONTH() Excel function, ex.: =MONTH(A1), etc.
2) To get the average from particular month, say September (9th month), you need to enter the formula:
= SUMIF(C:C,"=9",B:B)/COUNTIF(C:C,"=9")
If you want the average for different month, you just change the 9 in SUMIF and COUNTIF.
You could make a pivot table, then drag the date in row field and values in value field. Then change the field setting of the values to 'average'.

How do I write an excel formula to count the number of a value in one column based off of a date in another column?

I have a worksheet and I'm trying to do a simple Count function, probably a countif but I'm unsure how to go about writing the formula.
I have two columns that I'd like to use for this formula.
Column N - I would like to filter for the Criteria of "C" or anytime a cell has a value of C
Column 0 - This column has dates filled in (short date format).
I would like to get a count of every C for each month, as simple as that.
In this example I filtered the date for May of 2017 and filtered for C under the Check column. We can see that there are 12 instances of C showing in the month of May 2017.
Does anyone know how to structure a formula that I would be able to Count the Number of C's for every month into the foreseeable future?
I figured out how to count the total present in a date range but unsure of how to add the date range plus Column N (Check) every time "C" is present in the cell.
=SUMPRODUCT((O:O>=DATEVALUE("5/1/2017"))*(O:O<=DATEVALUE("5/31/2017")))
Try this
=COUNTIFS(O1:O100,">="&A1,O1:O100,"<"&B1,N1:N100,"C")
Where A1 has the start date and B1 has the end date for that month. You can use DATEVALUE() instead of A1 and B1. Change as applicable
Screenshot
If you want to use SUMPRODUCT then see this
=SUMPRODUCT((O:O>=DATEVALUE("1/5/2017"))*(O:O<=DATEVALUE("30/5/2017"))*(N:N="C"))
In another column (lets say 'P' for example) I would insert a formula to give you the month number =Month(P7) - this will return 5 for May.
I would then use COUNTIFS (Like COUNTIF but it uses multiple criteria) to count where column N contains 'C' and column 'P' contains '5'.
=COUNTIFS(N:N,"C",P:P,5)
Try this....you need to select the entire Column B and named the column as 'Date'.enter image description here

Sum of values for a given week

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.

Excel Formula to sum value if date falls in particular month

I am trying to make a table in excel which calculate sum of some values if a date falls in a particular month.
On the column A are dates, on column B some values, on column E are only listed numbers from 1 to 12 and in column F there are cells with =SUM(IF(MONTH($A$1:$A$10)=E11; $B$1:$B$10; 0)) formula.
I dont really know why on F9 the value is 0 even if checked with the debuger (F9 key) and saw that the result of the foruma is 22, which is the expected value. Also, I dont know why on F11 and F12 I receive an error: A value used in the formula is of the wrong data type
What can I do to solve this problems? Thank you
I solve the problem. I surounded the foruma with curly brackets ( { } ) and now works
For versatility and perhaps speed in a large spreadsheet I think you might consider a PivotTable. So label your two columns (say Date and Value), insert a PT with Date for ROWS and Sum of Value for VALUES, then Group..., Years (avoids summation of the same month but different year) and Months.

Find and sort same months name as single in Microsoft Excel 2007

I am working with Microsoft excel 2010. I have different dates like column E1:E19 that are not in specific interval. I want help to find only starts month date and paste them into G column like shown into the figure.
First of, is to say - both K_B and Ibrahim Odeh have valid and good attemps. I just want to add another option, because those options use additional rows or manual tools.
Here is the formula I came up with to solve this as shown in your screenshot - just one column, just the rows with the starting dates:
G1=SUBTOTAL(5,E$1:E$19)
G2=SUBTOTAL(5,OFFSET(E$1:E$19,MATCH(EOMONTH(G1,0),E$1:E$19,1),0,ROWS(E$1:E$19)-MATCH(EOMONTH(G1,0),E$1:E$19,1)))
It is possible to use this for the whole column, like this:
G1=SUBTOTAL(5,E:E)
G2=SUBTOTAL(5,OFFSET(E:E,MATCH(EOMONTH(G1,0),E:E,1),0,ROWS(E:E)-MATCH(EOMONTH(G1,0),E:E,1)))
And now, some explaining:
First, you need a starting point in G1 - so we use SUBTOTAL to get the earliest date in column E, using MIN (which is 5).
Now we work from here, by offsetting the range which we use to calculate our SUBTOTAL, still using MIN (5), to get the beginning of each month.
The trick is OFFSET. The first parameter is out basic range, which we will offset, then we have to determine how many rows to offset, and to not get an error, we use ROWS(basicRange) - rowOffset to always stay in out range.
MATCH is used to determine the necessary offset, by looking for the row of the last listed date of the month from G1 using EOMONTH.
Hope this clears any question.
Edit:
Because I do have to translate this, here is the original:
=TEILERGEBNIS(5;E:E)
=TEILERGEBNIS(5;BEREICH.VERSCHIEBEN(E:E;VERGLEICH(MONATSENDE(G1;0);E:E;1);0;ZEILEN(E:E)-VERGLEICH(MONATSENDE(G1;0);E:E;1)))
as long as your dates columns is sorted as it looks in the example then do the following:
insert a row above row 1 (for use of the formula)
enter a formula in column A in all rows that your table has. The formula reads:
=If(NOT(YEAR($E2)&MONTH($E2)=YEAR($E1)&MONTH($E1), MAX($F$1:$F1)+1, "")
This will add increasing numbers from 1 to the number of months involved only next to the first date in your table for that month.
Then in your table in column G put:
=VLOOKUP(ROW(), A:E, 5)
you can drag this formula down as far as you want. The formula finds the first record in A:E that matches the row number in G (ROW() in G1 returns 1), Then VLOOKUP() will return the value in the 5th column in A:E (which is column E with the date).
The Formula in column A should be to the left of the dates for the VLOOKUP() formula to work.
Alternatively you can put it in a column to the right but then use another formula in stead of VLOOKUP() in column G:
=SUMIF(F:F,ROW(),E:E)
This sums all values in E for rows where the value in F matches the row number of the cell in G.
I think you need to use analysis-toolpak Add-on to perform this task:
check out the following URL if you need to know how to load it:
http://office.microsoft.com/en-us/excel-help/load-the-analysis-toolpak-HP001127724.aspx
Regards

Resources