SUMPRODUCT difference between two dates for THIS WEEK entries only - excel

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.

Related

Excel how to convert weeknum to date when crossing the year

I have a table with Date column and weeknum column.
The weeknum column has below formula to create a srting: 2022/10.
=YEAR([#[Date]})&"/"&WEEKNUM([#[Date]],2)
I would like to get the start day and end day of the week converting from the string "2022/10".
I tried =DATE($M$1,1,-2)-(WEEKDAY(DATE($M$1,1,3))+(MID(M4,6,2)*7)) where $M$1 references current year and M4 references Year/ weeknum but it returns 10/17/2021. It should return 2/28/2022, and as the weeknumber increases. the returned dates decrease.
The dates of 2021/53 are correct, but the others got wrong.
How do I get fixed the dates?
You can do this by taking the weekday number of the date away from itself and adding 7-weekday to itself.
i.e.
If we use the first date on your list and we say weeks start on Monday:
The first day of the week (Monday) = E2-WEEKDAY(E2,2)+1 = 12/27/21
The last day of the week (Sunday) = E2+(7-WEEKDAY(E2,2)) = 01/02/22
Note: I have assumed your first date (12/27/2021) is in Cell E2
If you want Sunday to be the first day of the week, simply add a 1 instead of a 2 into the WEEKDAY part of the formula.

Return last day per month (and week) in dataset

I have a large amount of daily stock market closing data that I need to report on, however I only need the last day of the month from each data set.
Given the dates of each month will differ year to year depending on weekends and public holidays I can't just use =EOMONTH(A2,0)
How do I extract, just the last day of each month from a data set probably using the MAX functionality in some way. Then I can just do a Vlookup to get the data for that date,
[![Share Price Sheet][1]][1]
If your date column is sorted by small to large, index() and match() could solve this problem.
Try to use:
=INDEX(A:A,MATCH(EOMONTH(DATE(D2,E2,1),0),A:A,1))
which point is set third argument to 1 in MATCH function.
If you want to get close price, in G2 cell write:
=VLOOKUP(F2,A:B,2,FALSE)
Since the last date is found on the dataset you have, you can just select distinct your year & month in a new sheet, create a helper column combining the 2 columns.
Create the same helper column in your original dataset, sort dates by newest to oldest. And you can vlookup the exact date. If you just want the day part of the date, extract the date from the Date itself with the day formula
You can do this just by Pivot Table
Select your data (I used a snipped only)
Insert a Pivot Table
Use Year, Date and Close as your Row labels
Use Date also as a value field
Set Date in your value field to show Max, format to actually show dates and rename if you want, e.g. "Last Day"
Click any date under any month in the row labels > Filter > Top-Ten > Choose to filter top 1 under Last Day and confirm.
Format your pivot table to your liking, maybe hiding subtotals.
My end result looks like:
You could use a combination of EOMONTH and WORKDAY.
For example:
The date you're looking at is 21st November 2019.
=EOMONTH(DATEVALUE("21 Nov 2019"),0)+1 will return 1st December 2019.
30th November is a Saturday, and for some reason the 25th to 29th November are holidays.
=WORKDAY(EOMONTH(DATEVALUE("21 Nov 2019"),0)+1,-1,{43798,43797,43796,43795,43794}) will return 22nd November as last working day of the month.
Using cell references (D3 = Date, A1:A5 are the holidays):
=WORKDAY(EOMONTH(D3,0)+1,-1,$A$1:$A$5)

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

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

Find last digits with IF

I have lots of cells in the spreadsheet that contains the whole year, date and stock prices, but I only need the dates from 25th of the last month till the 5th of this month.How can I write a function to do that? For example if the cells are like this in the column:
19900101
19900102
19900103
19900104
19900105
.
.
19900125
19900126
19900127
19900128
19900129
19900130
19900131
I want it to show only days (1,2,3,4,5,25,26,27,28,29,30,31) with the date format.
The date shows in the text format and I've tried format cell to change it but it doesn't work.
For a slightly different approach, assuming you want to return the A2 value only if it represents a date in the last 5 or first 5 days of any month you can use this formula in B2
=IF(DAY(TEXT(A2,"0000-00-00")+5)<11,A2,"")
TEXT function converts your data to a real date then if you add 5 days to that date then any date that was originally in the last 5 or first 5 of the month will now be in the first 10 days of the month.....so it's sufficient to check that the day is < 11. That will pick up 27th to 31st of a 31 day month, 26th to 30th of a 30 day month etc.
you could use a formula and then filter by rows with data...
As an example (given it's difficult to discern if you always want the first 5 and last 5 of a month or what....)
=IF(RIGHT(A2,2)*1<=2,A2,IF(RIGHT(A2,2)*1>=29,A2,""))
Based on all the edits and comments, these should be the function you need.
=IF(OR(A7-A2>5,MOD(A2,100)<=5),DATE(LEFT(A2,4),MID(A2,5,2),RIGHT(A2,2)),"")
You should place it in cell B2 and then do all the desired filtering, as explained in xQbert's answer.

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