Get EndofMonth with weekNum and Year only

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
i only have year and weeknumber in my table. How can I get the End of Month date?

thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
This is the best I could manage: non sure about international WeekNum. Example: in A1 the year and in B1 the WeekNum, in C1 try:
=EOMONTH(DATE($A1,1,1)+($B1-IF(WEEKDAY(DATE($A1,1,1),2)<5,1,0))*7-WEEKDAY(DATE($A1,1,1),2)+1,0)
even this will probably work:
=EOMONTH(DATE(A1,1,B1*7-2)-WEEKDAY(DATE(A1,1,3)),0)
 
Last edited:
Upvote 0
This is the best I could manage: non sure about international WeekNum. Example: in A1 the year and in B1 the WeekNum, in C1 try:
=EOMONTH(DATE($A1,1,1)+($B1-IF(WEEKDAY(DATE($A1,1,1),2)<5,1,0))*7-WEEKDAY(DATE($A1,1,1),2)+1,0)
even this will probably work:
=EOMONTH(DATE(A1,1,B1*7-2)-WEEKDAY(DATE(A1,1,3)),0)
thanks. the 2nd formula works in Excel... I needed it for PQ, ill see if I can translate it with the PQ functions, if cant ill repost...

can you give me the logic of the 2nd formula. How does subtracting 3rd day in Jan make this work? or subtracting 2 ? whats the logic
 
Upvote 0
Sorry, I missed the detail :eek:.
no worries, tried to replicate in PQ and I get error... can you see the wrror???


Date.EndOfMonth(#date(Date.Year([Q4Dates]), Date.Month([Q4Dates]), [weekNum]*7-1))
- Date.DayOfWeek( Date.Year([Q4Dates], 1, 3))
 
Last edited:
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Week", Int64.Type}, {"year", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "WeekStart", each Date.StartOfWeek(Date.AddWeeks(#date(
[year], 1, 1), [Week]-1), Day.Monday)),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "EndofMonth", each Date.EndOfMonth([WeekStart]))
in
    #"Added Custom1"
1666192761934.png
 
Upvote 0
Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    fnEndOfMonth = (year as number, week as number) as date =>
        Date.EndOfMonth(List.Select(List.Transform({Number.From(#date(year,1,1)).. Number.From(#date(year,12,31))},
        (x)=> let df = Date.From(x) in {Date.WeekOfYear(df), df}), (y)=>  y{0}=week){0}{1}),
    tbl = Table.AddColumn(Source, "End of Month", each fnEndOfMonth([Year], [WeekNum]))
in
    tbl

Book1
ABCDEFG
1YearWeekNumYearWeekNumEnd of Month
220055120055112/31/2005
32003282003287/31/2003
42002232002236/30/2002
52005242005246/30/2005
62008292008297/31/2008
720214420214410/31/2021
820024820024811/30/2002
92009232009235/31/2009
102004242004246/30/2004
1120205120205112/31/2020
122008172008174/30/2008
1320175020175012/31/2017
141999281999287/31/1999
1520134420134410/31/2013
162007162007164/30/2007
172017112017113/31/2017
181999161999164/30/1999
19
Sheet1
 
Upvote 0
both work great,,, still working to understand functions.
 
Upvote 0

Forum statistics

Threads
1,223,603
Messages
6,173,302
Members
452,509
Latest member
CSHOCK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top