I have a spreadsheet that tracks average file processing times over the course of a month. One of the macros and stats that we like to pull, is performance on Mondays (as the files are a little built up over the weekend). The spreadsheet is organized into columns by weekdays of the month:
The dates are formatted MM/DD/YYYY, so I would think Excel has a date function that it can determine weekday based on that date value.
Currently, I just have to manually tell the Macro which columns are Mondays, like so:
=AVERAGE(B20,G20,L20,Q20)
So, instead of manually, how would I get the average over the range of say, B20
to V20
, only if the day of the week is Monday (the date cells are in row 1, so B1
to V1
)?
To determine the weekday of a date in EXCEL use the =WEEKDAY()
formula, which evaluates as 1 (Sunday) to 7 (Saturday)
eg If A1 contains 12/31/2016 (or 31/12/2016 if you're from where I'm from), the formual =WEEKDAY(A1)
would evaluate to 7 (indicating that the last day of 2016 was a Saturday)
To apply this formula to your problem: (assuming that the dates are in row 1 and the values are in row 2)
WEEKDAY()
value (say, row 2) =WEEKDAY(A1)
Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3)
If your date is in A1, you can use =Text(A1,"dddd")
to determine the day of the week (it will return the name, "Monday", "Tuesday", etc.) so then you could do perhaps:
=If(text(A1,"dddd")="Monday",[do whatever],[do whatever])
(may need a helper row/column to hold the text of the weekday)
(Or use AverageIf()
and use the Text()
idea.)
Possibly, you can add a column called [Day Of The Week] and use the following formula to display the day.
TEXT(B4,"dddd")
Then add an 'If'statement to your result cell.
simply
=SUMPRODUCT((MOD(B1:V1,7)=2)*B20:V20)/SUMPRODUCT((MOD(B1:V1,7)=2)*1)
should give the average of all values from B20 to V20 if the corresponding cell in row 1 is a monday.
the first part sums the values of all mondays and the second part counts them (sum / count = average) ;)
If you have any questions, just ask.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.