cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
misen13 Regular Visitor
Regular Visitor

Week of month from Calendar

Hi,

 

Is there a way to create a calendar of unique value of weeks?

IE: 01.01.2018 to 31.12.08 shows a column with 1/2018, 2/2018...52/2018

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ThomasFoster Established Member
Established Member

Re: Week of month from Calendar

This is very easy to do in Power Query using Date.WeekOfYear

 

 

The following PQ code will create a date table with the column you want

let
    EndDate = #date(2018,12,31),
    StartDate = #date(2018,1,1),
    DayCount = Duration.Days(Duration.From(EndDate - StartDate)) + 1,
    Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
    TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),
    ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}),
    RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}),
    AddedYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date]),Int64.Type),
    AddedWeekOfYear = Table.AddColumn(AddedYear, "WeekOfYear", each Date.WeekOfYear([Date]),Int64.Type),
    AddedWeekInYear = Table.AddColumn(AddedWeekOfYear, "WeekInYear", each Text.From([WeekOfYear]) & "/" & Text.From([Year]),Text.Type)
in
    AddedWeekInYear  

View solution in original post

2 REPLIES 2
ThomasFoster Established Member
Established Member

Re: Week of month from Calendar

This is very easy to do in Power Query using Date.WeekOfYear

 

 

The following PQ code will create a date table with the column you want

let
    EndDate = #date(2018,12,31),
    StartDate = #date(2018,1,1),
    DayCount = Duration.Days(Duration.From(EndDate - StartDate)) + 1,
    Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
    TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),
    ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}),
    RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}),
    AddedYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date]),Int64.Type),
    AddedWeekOfYear = Table.AddColumn(AddedYear, "WeekOfYear", each Date.WeekOfYear([Date]),Int64.Type),
    AddedWeekInYear = Table.AddColumn(AddedWeekOfYear, "WeekInYear", each Text.From([WeekOfYear]) & "/" & Text.From([Year]),Text.Type)
in
    AddedWeekInYear  

View solution in original post

Omega Established Member
Established Member

Re: Week of month from Calendar

@misen13 

 

Try creating a calculated table and call it calendar: 

 

Calendar = CALENDAR("01/01/2018","01/01/2030")

Then, create a calulcated column for weeks: 

 

Week = WEEKNUM('Calendar'[Date],2) &"/"&YEAR('Calendar'[Date])

Helpful resources

Announcements
Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors