Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
IF
Post Prodigy
Post Prodigy

Power query week number

Hi,

In power query i have a date table. I want to exract the number of the week. However it starts the week on Sunday. How can i change it and start the week from Monday. For example, I want to see 7 January 2024 in week 1 and day number should be 7.

 

Thanks in advance

 

Date table is:

let
Source = List.Dates(#date(2020,01,01), 365*7, #duration(1,0,0,0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Column1]), Int64.Type),
#"Inserted Week of Year" = Table.AddColumn(#"Inserted Year", "Week of Year", each Date.WeekOfYear([Column1]), Int64.Type),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Week of Year", "Day of Week", each Date.DayOfWeek([Column1]), Int64.Type),
#"Renamed Columns" = Table.RenameColumns(#"Inserted Day of Week",{{"Column1", "Date"}}),
#"Inserted Start of Week" = Table.AddColumn(#"Renamed Columns", "Start of Week", each Date.StartOfWeek([Date]), type date),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Start of Week",{"Start of Week"})
in
#"Removed Columns"

2 ACCEPTED SOLUTIONS
watkinnc
Super User
Super User

You can add the optional week start parameter to your Date.WeekOfYear, like

 

Date.WeekOfYear([Date], Day.Monday)

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

dufoq3
Super User
Super User

Hi @IF,

 

dufoq3_0-1711555103401.png

let
    Source = #table(type table[Date=date], {{#date(2024,1,7)}}),
    #"Inserted Week of Year" = Table.AddColumn(Source, "Week of Year", each Date.WeekOfYear([Date], Day.Monday), Int64.Type),
    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Week of Year", "Day of Week", each Date.DayOfWeek([Date], Day.Monday) +1, Int64.Type)
in
    #"Inserted Day of Week"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @IF,

 

dufoq3_0-1711555103401.png

let
    Source = #table(type table[Date=date], {{#date(2024,1,7)}}),
    #"Inserted Week of Year" = Table.AddColumn(Source, "Week of Year", each Date.WeekOfYear([Date], Day.Monday), Int64.Type),
    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Week of Year", "Day of Week", each Date.DayOfWeek([Date], Day.Monday) +1, Int64.Type)
in
    #"Inserted Day of Week"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

watkinnc
Super User
Super User

You can add the optional week start parameter to your Date.WeekOfYear, like

 

Date.WeekOfYear([Date], Day.Monday)

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.