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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
TechR21
Helper V
Helper V

Start and end of week with specific date & time

Hi,

 

i created 2 columns (week start date, and weeknum) based on a creationdate (format 08/11/2022 10:51:20)

 

I  start the week on a fri and end on a thursday with the following:

Week Start date(Fri-Thu) = 'Incidents'[created]+-1*if(WEEKDAY(Incidents[created])<6,WEEKDAY('Incidents'[created])+1,WEEKDAY('Incidents'[created])-6  )
 
With this i created another column to determine the weeknumber:
weeknummmer = WEEKNUM(Incidents[Week Start date(Fri-Thu)])
 
Now i want the same, but the week should start at fridays, at 17:00:00 and end at the next friday at 16:59:59
 
How do I include a specific time to determine the start and end of a week?
 
 
2 ACCEPTED SOLUTIONS
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @TechR21 - DAX does not have a Start of Week function, so this is reason why I suggested using Power Query instead.  If you need to use DAX you could consider the following:

Week Start date(Fri-Thu) = 
VAR _datetime = 'Incidents'[created]
/"Friday will equal 1*/
VAR _day = WEEKDAY( _datetime , 15 ) 
/*This returns the start of week based on Friday
VAR _StartOfWeek = 
      IF ( 
          AND( _day = 1 , HOUR ( _datetime ) >= 17 ), 
          DATE( YEAR( _datetime) , MONTH( _datetime) , DAY( _datetime ) ),
          IF ( AND( day = 1, HOUR ( _datetime ) < 17 ), 
               DATE( YEAR( _datetime) , MONTH( _datetime) , DAY( _datetime ) ) - 7,
               DATE( YEAR( _datetime) , MONTH( _datetime) , DAY( _datetime ) ) - _day + 1
      ) 
RETURN
    _StartOfWeek 

View solution in original post

Im getting the following error:

error.png

View solution in original post

6 REPLIES 6
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @TechR21 - DAX does not have a Start of Week function, so this is reason why I suggested using Power Query instead.  If you need to use DAX you could consider the following:

Week Start date(Fri-Thu) = 
VAR _datetime = 'Incidents'[created]
/"Friday will equal 1*/
VAR _day = WEEKDAY( _datetime , 15 ) 
/*This returns the start of week based on Friday
VAR _StartOfWeek = 
      IF ( 
          AND( _day = 1 , HOUR ( _datetime ) >= 17 ), 
          DATE( YEAR( _datetime) , MONTH( _datetime) , DAY( _datetime ) ),
          IF ( AND( day = 1, HOUR ( _datetime ) < 17 ), 
               DATE( YEAR( _datetime) , MONTH( _datetime) , DAY( _datetime ) ) - 7,
               DATE( YEAR( _datetime) , MONTH( _datetime) , DAY( _datetime ) ) - _day + 1
      ) 
RETURN
    _StartOfWeek 

Im getting the following error:

error.png

Sorry I missed an "_" before day on Row 8

Yes now it working, and exactly the results I expected! Thank you so much!

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @TechR21 - I would like to recommend using Power Query to add a new column which returns the StartOfWeek.  Something like the following:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc8xCsAgEETRu1gr7ExMFM+RTrz/NZIyAT9s9Zs3O2dy2EUqilt1RLyXVv73E/oFvUHvuy5wBa7AFbgC1+Ae4Na9a/jX3z3rAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Week Beginning", each if 
                    Date.DayOfWeek( [Column1] , Day.Friday ) = 0 
                        and 
                    Time.Hour( Time.From( [Column1] ) ) >= 17 
                        then
                    Date.From( Date.StartOfWeek([Column1] , Day.Friday ) )
                        else 
                    Date.From( Date.StartOfWeek([Column1] , Day.Saturday ) ) - #duration(1, 0, 0, 0)
            , type date)
in
    #"Added Custom"

 

thank you, but I really just want to add the time in my previous created column as asked. If not possible I can try other things.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors