Excel - how to get if a date is a specific day of the week? - excel

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)
e.g. 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)
insert a new row to hold the WEEKDAY() value (say, row 2)
in cell A2 type in =WEEKDAY(A1)
copy this formula as far right as necessary (to include all your dates)
Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3)

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.

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.)

Related

SUMPRODUCT difference between two dates for THIS WEEK entries only

I have a column D containing all the Dates in DD/MM/YYYY format, and I would like to show the count of missed days for THIS WEEK values only from all the entries in column D.
In other words, if there is a difference between two Dates in column D and it occured this week, I would like to count it.
I have below formula to calculate "Total days missed" between first and the last entry in Dates column D, however I can't adopt this formula to display "Days Missed" for THIS WEEK only entries.
=SUMPRODUCT(--ISNA(MATCH(ROW(INDIRECT(MIN($D$18:$D$500)&":"&MAX($D$18:$D$500)));$D$18:$D$500;0)))
Sample of data set.
Please help, thanks.
For O365, in accord with your statement that there can be multiple entries of one date, I suggest the following (assuming your dates are real dates and not text strings that happen to look like dates):
Total Missing Dates
=MAX($D$18:$D$500)- MIN($D$18:$D$500)+1-COUNT(UNIQUE($D$18:$D$500))
Missing Dates THIS WEEK obviously, you'll need to define the first and last dates of THIS WEEK
=7-COUNT(FILTER(UNIQUE($D$18:$D$500),(UNIQUE($D$18:$D$500)>=wkStart)*(UNIQUE($D$18:$D$500)<=wkEnd)))
If your week starts on Monday, you can calculate:
wkStart: =TODAY()+1-WEEKDAY(TODAY()-1)
wkEnd: =wkStart+6
More generally, to return a particular day of the week prior to someDate (or wkStart):
wkStart = someDate - WEEKDAY(someDate - DayOfWeek)
where DayOfWeek is: Sunday=1 Monday=2 , etc
So, making someDate = TODAY()+1 ensures that if today is monday, it will return today and not the monday from a week ago.
HINT: It might be more convenient to define wkStart and wkEnd as a Named formula.

VBA, change part of date in cell

I have a large sheet of data where i need to change the date (day) in 4 or 5 columns to match the date (day) in another column. For example in 'H' i have 16/05/15 etc. and in the other columns all the days are the 1st of the same month. I would like to change the day '1' to the same day '16' as in column 'H' it will take me hours to do, can anyone help me out with some code that would do it for me?
Thanks.
If this is a one-off, you could just write a formula in a temporary column that calculates DATE using the YEAR and MONTH of the original cell and the DAY of column H (watching out for 29th of Feb in non-leap years, if the year in H is different to the year in the other cell), and then "paste values" that result back over your original cells.
For example, assuming data you want to change is currently in K2, then place the following formula in X2 (or wherever else you like):
=IF(MONTH(DATE(YEAR(K2),MONTH(K2),DAY(H2)))<>MONTH(K2),
DATE(YEAR(K2),MONTH(K2)+1,0),
DATE(YEAR(K2),MONTH(K2),DAY(H2)))

Excel SUMIFS Statement - Calculate profit for each month across multiple years

I've got three columns of data.
Sell Date - Column G - Contains the day, month and year in dd/mm/yyy format.
Month (calculated from sell date) - Column I - Contains month number
Profit - Column M - Profit in Dollars.
I am trying to calculate the profit made in each month and year.
Current formula using SUMIFS. I look at the data in Column I and if this contains a 1, and if G contains the year 2016 then it's January 2016. Think it's the year function that I don't quite get.
=SUM(SUMIFS(M9:M50, I9:I50, {"1"}, G9:G50, YEAR=2016))
You can create another column that shows just the year year(G2) or you can use this formula
=SUMIFS(M9:M50,G9:G50,">=1/1/2016",G9:G50,"<1/2/2016")
I also like this formula that allows you to reference the date in one cell and calculate a 1 month range. Put 01/01/2016 in cell A1 and the formula does the rest.
=SUMIFS(M9:M50,G9:G50,">="&A1,G9:G50,"<" & EDATE(A1,1))
The SUMIFS function doesn't like it when you alter the value of the IF parameters. It would be better to use a SUMPRODUCT formula to calculate this, for example:
=SUMPRODUCT((M9:M50)*(I9:I50=1)*(YEAR(G9:G50)=2016))
Where:
(M9:M50) are the values you wish to SUM.
(I9:I50) are the month values and 1 is the month you wish to specify.
(G9:G50) are the date values you wish to obtain the year from and 2016 is the year you are specifying.

count occurrences of a word within a date range like month or quarter

I have a sheet with data organized by date for an entire year. Column "a" would be the dates in chronological order and column "b" would have a name in each cell. Many of the names are repeated throughout the year.
What formula would I use to count how many times a particular name was listed in column b within a particular month, quarter or date range of my choice?
I would like to create a new sheet to show this data once I have the proper formula/s.
I am using excel 2016
OK, let's specify your inputs like this:
E1: name
E2: start date
E3: end date
Then to do the calculation:
=CountIf( B:B,E1, A:A,">="&E2, A:A,"<"&E3 )
So for 2016 you'd put 2016-01-01 in E2 and 2017-01-01 in E3.
(If you use "<=" and 2016-12-31 for the end of the year, you run a slight risk that a date+time combination for the last day of the year will be excluded. Better to always use lower<=x and x<upper to avoid this.)

How to get the week number of the year from the date range in an Excel Pivot Table

Hi I would like to know a formula where I can convert a grouped date range into the week number of the year. For example column A has the date ranges. I want column B to have the week number. So it will be like the example below
Column A Column B
31/12/2013 - 06/01/2013............................................Week 1
07/01/2013 - 13/01/2013............................................Week 2
Thanks to anyone who can solve this. Its been bugging me out
You could perhaps use something like that:
=(RIGHT(A2,10)*1-41273)/7
This takes the last date in that date range, turns it into a number and subtracts 41273 (which is the equivalent of 1st January 2013) and divides the result by 7.
If you want to specifically get Week 1, you can either use custom formatting with "Week "#, or if you want the literal Week, you can use ="Week "&(RIGHT(A2,10)*1-41273)/7

Resources