Dynamically change the number of days in a month for dropdown - excel

It has to be done without VBA.
I have a list of months to be filled in one cell, say A1. The options can be filled using Data Validation-List (=Months) which causes a dropdown to appear in A1. In cell B1 I enter a year number (for example 2000).
Now I want C1 to contain a dropdown, the entries in which change on the basis of the data in A1 and B1. In my example, A1 offers the choices january, february, march, april, may, june, july, august, september, october, november and december.
If I select january or march or may or july or august or october or december (months with 31 days), I should get numbers between 1 and 31 as an option in C1.
If I select april or june or september or november (months with 30 days), I should get numbers between 1 and 30 as an option in C1.
If I select february, I must first check if an year is leap year with this formula:
=((MOD(B1;4)=0)*((MOD(B1;100)<>0)+(MOD(B1;400)=0))=1)
and based on result of this formula(TRUE or FALSE), I should get numbers between 1 and 28 (or 29 if is leap year) as an option in C1.
I have created lists, named Days30, Days31, Days28 and Days29. How can I use Data Validation to switch between those lists for my dropdown in C1?? I'm trying to translate this logic into Data Validation formula, but no luck:
If (A1 = "april" OR A1 = "june" OR A1 = "september" OR A1 = "november") Then
Days30
ElseIf (A1 = "february" AND leapyear = 1) Then
Days29
ElseIf (A1 = "february" AND leapyear = 0) Then
Days28
Else
Days31
End if

In Z1 put this formula, =DAY(DATEVALUE(A$1&" "&ROW(1:1)&", "&B$1))
In Z2 put this formula, =IFERROR(IF(MONTH(DATEVALUE(A$1&" "&ROW(1:1)&", "&B$1))=MONTH(DATEVALUE(A$1&" "&ROW(2:2)&", "&B$1)), DAY(DATEVALUE(A$1&" "&ROW(2:2)&", "&B$1)), ""), "") ... and fill down to Z31.
Go to Formulas ► Defined Names ► Name Manager. When the Name Manager dialog opens, click New.
Give it a name (e.g. lstDOM), leave it as Workbook scope and supply the following for the Refers to: =Sheet1!$Z$1:INDEX(Sheet1!$Z:$Z, MATCH(1e99, Sheet1!$Z:$Z))
Click OK to create the dynamic named range then Close.
With C1 selected, go to Data ► Data Tools ► Data validation. Choose Allow: List and supply =lstDOM for the Source:.
Your results should resemble the following.
      

Related

excel formula for previous quarters

I am looking for a formula to pull up the previous quarter and year like in the Column J, for the Oct 20, it should return Q3 20 instead of Q4 20.
Currently my formula only returns the correct quarter but I would need the previous to last quarter and year?
To return the quarter | year corresponding to 3 months ago, i.e. :
"previous quarter & year"
simply replace col H date references with edate(date,-3). Cell J17 formula to enter is then:
="Q"&ROUNDUP(MONTH(EDATE(H17,-3))/3,0)&" "&YEAR(EDATE(H17,-3))
If you have Office 365 compatible version of Excel, you could shorten (albeit ever so slightly in this case) with the let function as so:
=LET(x,EDATE(H17,-3),"Q"&ROUNDUP(MONTH(x)/3,0)&" "&YEAR(x))

How to create different date ranges based on criteria?

I have a table with two active columns. In Column A I have all the dates between, let`s say, January 1, 2012 to December 31, 2019. In column B I have a corresponding name. For instance:
[
etc.
I want to create ranges based on criteria, like:
The trick is, this should be done by calendar year, which means that during the 8-year period, I should have 8 set of 3 columns (from / to / name), one for each calendar year. If one range covers two years (let's say, November 1, 2012 to February 1st, 2013), the last row of 2012 should read
2012-11-01 to 2012-12-31
while the first row of 2013 will read
2013-01-01 to 2013-02-01
I managed to separate the ranges, but for some reason I am not able to go further and do that for each calendar year. Is there a way to do that?
Let's assume you want to place your 8 set of 3 columns starting from column G and that your list in the range D:F has headers in row 1 and data from row 2 on. In cell G1 write down your first year (2012), in cell H1 "From", in cell I1 "To" and in cell J1 "Name".
Now in cell H2 write this formula:
=IF(IF(OR(IF(AND($E2>=DATE(G$1,1,1),$D2<=DATE(G$1,12,31)),1,0),IF(AND($D2>=DATE(G$1,1,1),$E2<=DATE(G$1,12,31)),1,0)),1,0),MAX($D2,DATE(G$1,1,1)),"")
In cell I2 write this formula:
=IF(IF(OR(IF(AND($E2>=DATE(G$1,1,1),$D2<=DATE(G$1,12,31)),1,0),IF(AND($D2>=DATE(G$1,1,1),$E2<=DATE(G$1,12,31)),1,0)),1,0),MIN($E2,DATE(G$1,12,31)),"")
In cell J2 write this formula:
=IF(AND(H2<>"",I2<>""),F2,"")
Drag the 3 of them all the way down accordingly to your need. You can then copy the G:J range and paste any time you need next to itself; just change the year in the top left cell and it should do the trick.
Report any question you have or bug you have encountered. If, according to your judgment, this answer (or any other) is the best solution to your problem you have the privilege to accept it (link).

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

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.

How to Display months based on the Quarter Selection

I have 2 columns in Excel sheet, Column1 has the Quarter Selection dropdown box(Q1, Q2, Q3 and Q4). And Column2 has the month selction dropdown box.
I need help in the below.
Q1 - Feb, March, April
Q2 - May, Jun, July
Q3 - Aug, Sep, Oct
Q4 - Nov, Dec, Jan
Now if a user selects Quarter as Q2 in Column1, the Dropdown values in Column2 has to have only May, June and July.
I tried the grouping option but it doesn't help me.
Thanks in Advance,
Satish D
You should create two tables, one containing quarters, and other containing all quarters with corresponding months (tables are surrounded with thick border).
Then in cell A2 create simple data validation and set list in D1:D4 as source.
In cell B1 also create data validation list, set allow to list, and in formula area please enter this formula =OFFSET(INDIRECT(ADDRESS(MATCH($A$1,E1:E12,0),5)),0,1,3,1)
You data validation list in cell B1 is now dependent on selection in list A1.

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

Resources