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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jschnur
Regular Visitor

Filtering in query by last week

 I Need last week to start on last Monday and go through Sunday. 

Is there a place or method to set the configuration to start the week on monday  instead of starting it on sunday.

 

There must be configuration parameters somewhere to define the start of week.

 

The Specific example I am querying form an excel file where a column is date and it has the entire years data i am trying to make a graph of last week. I need it to be last monday thru last sunday. it currently returns last sunday through last saturday.

2 ACCEPTED SOLUTIONS
MarcelBeug
Community Champion
Community Champion

The start of the week can be influenced by options - Regional Settings - Locale.

E.g. Dutch (Netherlands) has Monday as first day of the week.

 

To be independent of these settings, you can use function Date.StartOfWeek to calculate the first date of a week.

This function has a parameter for the first day of the week:

 

Date.StartOfWeek(dateTime as any, optional firstDayOfWeek as nullable number) as any

 

Example code with various options:

 

let
    Source = List.Dates(#date(2017, 5, 15), 30, #duration(1, 0, 0, 0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Date.IsInPreviousWeek", each Date.IsInPreviousWeek([Date])),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Date", type date}, {"Date.IsInPreviousWeek", type logical}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "StartOfCurrentWeek", each Date.StartOfWeek(DateTime.Date(DateTime.LocalNow()),Day.Monday)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "In Previous week", each [Date] >= Date.AddDays([StartOfCurrentWeek],-7) and [Date] < [StartOfCurrentWeek], type logical)
in
    #"Added Custom2"
Specializing in Power Query Formula Language (M)

View solution in original post

v-ljerr-msft
Employee
Employee

Hi @jschnur,

return_type A number that determines the return value: use 1 when the week begins on Sunday; use 2 when the week begins on Monday. The default is 1.

Return type: 1, week begins on Sunday. Weekdays are numbered 1 through 7.

Return type: 2, week begins on Monday. Weekdays are numbered 1 through 7.


In addition, you should also be able to set the return_type value of WEEKNUM Function (DAX) to 2 in this scenario. Smiley Happy 

=WEEKNUM("Feb 14, 2010", 2)

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @jschnur,

return_type A number that determines the return value: use 1 when the week begins on Sunday; use 2 when the week begins on Monday. The default is 1.

Return type: 1, week begins on Sunday. Weekdays are numbered 1 through 7.

Return type: 2, week begins on Monday. Weekdays are numbered 1 through 7.


In addition, you should also be able to set the return_type value of WEEKNUM Function (DAX) to 2 in this scenario. Smiley Happy 

=WEEKNUM("Feb 14, 2010", 2)

 

Regards

MarcelBeug
Community Champion
Community Champion

The start of the week can be influenced by options - Regional Settings - Locale.

E.g. Dutch (Netherlands) has Monday as first day of the week.

 

To be independent of these settings, you can use function Date.StartOfWeek to calculate the first date of a week.

This function has a parameter for the first day of the week:

 

Date.StartOfWeek(dateTime as any, optional firstDayOfWeek as nullable number) as any

 

Example code with various options:

 

let
    Source = List.Dates(#date(2017, 5, 15), 30, #duration(1, 0, 0, 0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Date.IsInPreviousWeek", each Date.IsInPreviousWeek([Date])),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Date", type date}, {"Date.IsInPreviousWeek", type logical}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "StartOfCurrentWeek", each Date.StartOfWeek(DateTime.Date(DateTime.LocalNow()),Day.Monday)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "In Previous week", each [Date] >= Date.AddDays([StartOfCurrentWeek],-7) and [Date] < [StartOfCurrentWeek], type logical)
in
    #"Added Custom2"
Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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