Generate start date, end date and week numbers belong to given start and end date - excel

I want generate week no list and start date and end date for particular week by giving some date range and I did as using below formaula.But I want consider all dates after belong to week 52 as week 1.my formulas working well if start and end dates belong to same year.But if I select start date after 26th dec like my formulas doesnt work.Please help.I consider monday to sunday.If I select dec29 it shows incorrect data(red highlighted)
A1-Start date(this is giving by calender picker)
B1-End Date((this is giving by calender picker)
A3 =IF(A1="","",YEAR(A1))
B3 =IF($A$1-WEEKDAY($A$1,3) +((ROW()-3)*7) <= $B$1-WEEKDAY($B$1,3), ISOWEEKNUM($A$1-WEEKDAY($A$1,3)+((ROW()-3)*7)), "")
C3 =IF(DATE(YEAR(B1),MONTH(B1),DAY(B1))>=DATE(YEAR(A1),MONTH(A1),DAY(A1)),IF(A1<>"",A1,""),"CHECK DATE RANGE")
D3=IF(DATE(YEAR(B1),MONTH(B1),DAY(B1))>=DATE(YEAR(A1),MONTH(A1),DAY(A1)),IF(B1<>"",MIN(DATE(A3+1,1,2),(DATE(A3,1,1)-WEEKDAY(DATE(A3,1,1),2)+B3*7)),""),"CHECK DATE RANGE")
I Want result as below

These formulas will work in Row 3:
A3 =IF(ISNUMBER($A$1),YEAR(A1),"")
B3 =IF(ISNUMBER($A$1),WEEKNUM($A$1,2),"")
C3 =IF(ISNUMBER($A$1),$A$1-WEEKDAY($A$1,2)+1,"")
D3 =IF(ISNUMBER($A$1),$A$1+6-WEEKDAY($A$1,2)+1,"")
Starting in Row 4, enter these formulas, then use the auto-fill cursor (select cells A4:D4, then click and hold on the lower-right corner icon of the selection box) to copy-fill as many rows down as you need.
A4 =IF(ISNUMBER($D3),IF(($D3+1)<$B$1,YEAR($D3),""),"")
B4 =IF(ISNUMBER($D3),IF(($D3+1)<$B$1,WEEKNUM($D3,2),""),"")
C4 =IF(ISNUMBER($D3), IF( ($D3+1)<$B$1, $D3+1,""),"")
D4 =IF(ISNUMBER($C4),$C4+6,"")
By the way, you mentioned in your post that you wanted Monday as the start of the week. So I used the value 2 in both WEEKNUM and WEEKDAY. Use a different value for other days if needed.

Related

excel - drop down list with condition

Maybe the title of the question is wrong, but I'll try to explain what I'm looking for. I have in cell A1 a drop down list to select months (from 1-12). Is it possible to automatically fill the rest of the A column with hourly data for the whole selected month. For example if it's selected "3" in A column'd be:
Time
1.3.2018 1:00:00
1.3.2018 2:00:00
1.3.2018 3:00:00
...
31.3.2018 22:00:00
31.3.2018 23:00:00
1.4.2018 0:00:00
Maybe, something like second drop down list.
Or maybe, it can be done with substitute, but then some months have 31 days, some 30, and february 28, and there is a problem with daylight saving time. In 3rd month, there's one day where I need to have 23 hours (jump from 02:00 to 04:00), and in 10th month one day with 25 hours (02:00, 02:00, 03:00).
In cell A2 enter the following formula:
=DATE(2018,A1,1)
Then custom format the cell with type:
d.m.yyyy hh:mm:ss
In Cell A3 enter the following formula:
=A2+1/24
And change the cell format as above, then drag the cell down to autofill until you have the full month.
There would be multiple ways, but one way is to first determine number of rows required (for March it would be 31 * 24 = 744), set first row using DATE function and then keep adding 1 hour until the desired row number is reached.
Calculate number of rows required in A2: =DAY(EOMONTH(A3,0))*24+ROW()
in A3 enter =DATE(YEAR(TODAY()),A1,1)
in A4 enter =IF(ROW()<=$A$2,A3+1/24,"") and drag down till about 800.
This will make it dynamic for number of days in month

Get user input for month and year to populate cells with dates of that month and year in excel

i want to take two inputs from user Year and month and then populate the cells with the dates of that month and year in excel.
for example:
Enter year:2017
Enter month:Jan
Date
1/1/2017
1/2/2017
1/3/2017
1/4/2017
.
.
.
.
the cells should auto populate when the month and year is entered.
thanks for suggestions in advance.
Without context, it's not clear what you need. Do you want the user to enter the data in dialog boxes or enter the data into two cells? What format will the user be expected to enter the dates in? For example, should January be entered as "Jan", "January", "1" etc.? You probably just need to have 31 formulas set up that reference the input cells, but you need to specify exactly how that input is handled first.
EDIT:
That was meant to be a comment, not an answer, so here is my actual answer:
In cell A1, set up a data validation rule. The rule should be a list with the source given as "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" or the longer form if you prefer. Now when you try to edit this cell you have the option of selecting from a drop-down list of months.
If you want to limit the year range as well, you can do something similar in cell B1. Just create comma-separated list of valid years in the source field.
Enter the numbers 1 to 31 in cells A3 to A33 then enter this formula in cell B3:
"=DATEVALUE(A3&"-"&$A$1&"-"&$B$1)"
Autofill/copy that down to B33. The DateValue function takes the calculated string (for example "13-Feb-2017") and converts it to a date which you can then format any way you want. Note that this will produce the error "#VALUE!" if either of the input cells are blank or if the choosen month doesn't have 31 days, but you can modify it to your own needs.
Assume this.
Cell b1 tooks input as month, create a name range rng
cell d1 tooks input as year, create a name range yearsamp
column I and J have this, with a formula in j3.
=IF(MOD(yearsamp,4)=0,29,28)
month days
1 31
2 29
3 31
4 30
5 31
6 30
7 31
8 31
9 30
10 31
11 30
12 31
name above cell range as monthdays
use this formula in A2 and fill
=IF(VLOOKUP(mnth,monthdays,mnth,FALSE)>=ROW(A2)-1,DATE(yearsamp,mnth,ROW(A1)),"N/A")
This is another option to achieve this
You can use this formula also.set up as said above.
on first field for 1st date enter this on A2
=DATE(d1,MATCH(b1,I1:I12,0),1)
On A3 write this forula and fill
=IF(ROW(a2)-1<VLOOKUP(mnth,mnthdays,2,FALSE),a2+1,"")
As you have 31 cells with formula it return errors when the month day count are less than 31 but this formula show those as blank without errors.

Calculate updated workdays from today

I have the following formula:
=NETWORKDAYS.INTL(C7,TODAY(),$E$2:$E$500)
Which I want to calculate the working days from the starting of the month (c7) to present day today. However I am getting a #num error any suggestions?
Example.
6/01/16 - today (6/21/16) = 15
tomorrow
6/01/16 - today (6/22/16) = 16
I'm doing a sales per day average that's why I would like it to update based on the date.
Assuming your data is in column A and you want result in column B. Place this formula in Cell B2 and drag it down.
=NETWORKDAYS(A2,TODAY())
Here is the data that I've used.
In cell B4, I have added +1 in formula just to show you the result based on tomorrow's date.
You will need to change the reference.

Excel | Formula to find total amount in this situation

Assume that we are currently in the month March. I have a table with all the months and a list of products. Inside each column i have the number sales a product has made on that month, like so:
Notice i have a cell containing "Total until current month". I would require a formula to find out the total amount of sales of a specific product (product A for example) up until March (current month) as you can see with the manually typed 6, 1 in Jan and 5 in Feb.
I would usually do this by finding the sum of cell C4 and D5. But this should be 1 dynamic formula that is updating as we progress onto next month. So as an exammple, in April, it will find the sum of cell C4 - E5 (Jan - March) and update the value.
Is this possible?
Regards
Put a helper row above the month names that has the month numbers 1-12.
Then use SUMIFS():
=SUMIF($C$2:$N$2,"<=" &MONTH(TODAY()),C4:N4)
You could hide that row so it is not visible and not readily accessible.
In row 3 put month numbers. Now if in cell Q4 you have a month number that you want to relate to use:
=SUMIF($C$3:$N$3,"<"&$Q$4,C5:N5)
for sum of A and drag down for other products.
If you want to pick the product you want sum for and have it all in one cell, then assuming that in cell R4 you have your product name (e.g. "B") write
=SUM((C3:N3<Q4)*C5:N6*(B5:B6=R4))
and press ctrl+shift+enter.
The simplest solution is to leave E4 through N4 empty. Only put a value in E4 once March is complete and you have a value for March. This will allow a formula like:
=SUM(C4:N4)
for Product A

How To automatically calculate Qtr Revenue given only two dates and Total Revenue

I could use some help writing an excel formula.
Case: Revenue is generated between 2 dates, Date A and Date B.
These dates could go into the next year and spread across quarters.
How can I split Revenue into Q1 Revenue, Q2 Revenue, Q3 Revenue, Q4 Revenue just based on my 2 dates and Total Revenue.
My thought was first identify which Qtr your dates fall into and then have an if statement that logically figures out the % and multiplies by the revenue.
Currently I'm using this formula to determine Qtr: =ROUNDUP(MONTH(DateA)/3,0).
Similarly for DateB.
Then, =if(DateAQtr=2, ((6/30/2013-DateA)/(DateB-DateA))*Revenue, 0)
There are clearly problems with this like, what happens if DateB(end Date) is in Q1 of the following year.
Denominator will always be Date B - Date A, giving you total days.
Numerator of Start Qtr is =(LastDayofQtr - Start).
Numerator of any quarters in the middle will be the full qtr length.
Numerator of End Qtr is =(EndDate - LastDayofPreviousQtr).
This is the logic. I'm trying to write into Excel formula to automate the process.
I made some named ranges to help see what is going on.
A2 = DateA, B2 = DateB, C2 = Revenue
A7 =DATE(YEAR(DateA),1,1) This is to establish the Q1 date for the DateA entered.
A8 =EDATE(A7,3) dragged down to cell A15 as in the picture. This returns the start of the next Quarter.
B7 =IF(AND(DateA>=A7,DateA<A8),A8-DateA,IF(AND(DateB>=A7,DateB<A8),DateB-A7,IF(AND(A7<DateB,A7>DateA),A8-A7))) This is checking how the dates compare to the Quarter start dates and returning the number of days our DateA and DateB date range contain for each Quarter.
C7 ="Q"&ROUNDUP(MONTH(A7)/3,0) dragged down to read the Qtr Start Date and return the corresponding Q#.
D7 =IF(B7=FALSE,"",C7&"-"&YEAR(A7)) returns the Q# and year when the days column is not false.
E7 =IF(D7="","",(Revenue/(DateB-DateA)*B7/Revenue)) This calculates the percentages of revenue that each quarter contains.
If you change the values of DateA or DateB everything still calculates properly. If you date range is larger than the two years displayed just drag the formulas down to expand the max range.
I hope this helps.

Resources