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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
gfo
Frequent Visitor

Week Number from a Custom of Start Month

Hi,

I need to be able to determine week number from our own custom start of month. For instance, Our February, 2020 Fiscal Month started on 26th January, 2020 and will end on 25th Febraury, 2020.  March will start on 26th February.

 

Our week starts on a Tuesday. How do I determine the week number from our Fiscal Start of Month? That is having 28th January to 3rd February being WEEK 1?

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @gfo 

As tested, i can get the results below:

2020 fiscal year start from 2020/1/26, 

2020/1/28-2020/2/3 as week2,

Capture8.JPG

Query1: create date table

(start_Date as date, end_date as date)=>
let
    duration_days=Duration.Days(end_date-start_Date),
    Source = List.Dates(start_Date,duration_days,#duration(1,0,0,0))
in
    Source

Query2:  Date
let
    Source = #"create date table"(#date(2020, 1, 1), #date(2020, 12, 31)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "date"}}),
    #"Inserted Month" = Table.AddColumn(#"Renamed Columns", "Month", each Date.Month(Date.AddDays([date],-25))),
    #"Added Custom" = Table.AddColumn(#"Inserted Month", "Custom", each Date.AddDays([date],-25)),
    #"Inserted Week of Year" = Table.AddColumn(#"Added Custom", "Week of Year", each Date.WeekOfYear(Date.AddDays([date],-25),Day.Friday)),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Week of Year",{"Custom"}),
    #"Inserted Year" = Table.AddColumn(#"Removed Columns", "Year", each Date.Year(Date.AddDays([date],-25)))
in
    #"Inserted Year"

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @gfo 

As tested, i can get the results below:

2020 fiscal year start from 2020/1/26, 

2020/1/28-2020/2/3 as week2,

Capture8.JPG

Query1: create date table

(start_Date as date, end_date as date)=>
let
    duration_days=Duration.Days(end_date-start_Date),
    Source = List.Dates(start_Date,duration_days,#duration(1,0,0,0))
in
    Source

Query2:  Date
let
    Source = #"create date table"(#date(2020, 1, 1), #date(2020, 12, 31)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "date"}}),
    #"Inserted Month" = Table.AddColumn(#"Renamed Columns", "Month", each Date.Month(Date.AddDays([date],-25))),
    #"Added Custom" = Table.AddColumn(#"Inserted Month", "Custom", each Date.AddDays([date],-25)),
    #"Inserted Week of Year" = Table.AddColumn(#"Added Custom", "Week of Year", each Date.WeekOfYear(Date.AddDays([date],-25),Day.Friday)),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Week of Year",{"Custom"}),
    #"Inserted Year" = Table.AddColumn(#"Removed Columns", "Year", each Date.Year(Date.AddDays([date],-25)))
in
    #"Inserted Year"

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jimmy801
Community Champion
Community Champion

Hello @gfo 

 

Try this custom function. They will only work for 2020

(dDate as date)=>
    let
        DayCustomCalendarWeek = Duration.TotalDays(dDate - #date(2020,1,26)),
        Weeknumber = Number.RoundUp(DayCustomCalendarWeek/7)+1
    in
        Weeknumber

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors