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

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

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.

excel nearest due date

I have a row with dates and below it I have an empty row where I can type a "C" on any number of cells wanted or needed to get the dates above it, but I only get the first C, so what I am trying to do is actually ignore every "C" that I have wrote that correspond to past dates from today and only give me the closer one or next one from today.
For example: lets say that today is July 1 2018, so I have row 1 with a series of dates like A1=June 30 2018, B1= July 1 2018, C1=July 2 2018, D1=July 3 2018, etc and in row2 I have typed C on A2, C2 and E2 so with HLOOKUP it returnsJune 30 2018`, but I dont want that since that date is now in the past, I want to get the next and more close date after the present day so it should be C2 that is July 2 2018, and so on since the today formula will update as the days pass.
This is to get the next checking date on a project cronogram so all the dates are defined but the result as for each task should be automatically updating to stay relevant for the scehdule, so past dates just dont make any sence to be the results showed on the gantt table diagram, and yes I know it is easy as just to be deleating the "C" that correspond to past dates, but then what is the point of excel then?
I'll go out on a limb here.... you want to find the first C in row 2 after todays date which is in row 1.
MATCH will tell you which column todays date is in: MATCH(TODAY(),$1:$1,0) returns 3 as 2nd July is in C1.
INDEX will return a reference to the cell below todays date when used in conjunction with MATCH: INDEX($2:$2,,MATCH(TODAY(),$1:$1,0))
COUNTA will tell you the last column that's populated with dates in row 1: COUNTA($1:$1) returns 9 in my case as I've put dates from A1:I1.
Use INDEX again to return a reference to the last cell in row 2. INDEX($2:$2,,COUNTA($1:$1))
Stick both INDEX's together to get a range reference from todays date to the end of you data: INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)) - this returns an error as it's returning the reference to multiple cells.
Now find the first C in the referenced range: MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0) returns 1 as I've got a C in 2nd July.
Add the column that todays date is on to the column that was returned (and minus 1 for the hell of it). SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0)) returns the column number of the first C on or after todays date.
Use that number to return a reference to the date in row 1: =INDEX($1:$1,,SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0))).
So your final formula is:
=INDEX($1:$1,,SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0)))
Bit long, and I'm sure it can be done in a much shorter formula.
Edit: I also agree with Rawrplus - you could've explained it a bit better.

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.

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

Resources