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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
mcnater
Advocate I
Advocate I

Week Start calculation

I'd love to be able to group my dates into Week Start buckets. In Qlikview there is a WeekStart() function where you provider a date and it groups dates into weeks, depending on the date and offset you provider so you can easily do this. I'm not finding something similar in PBI yet. Does anyone know how to do this?  Basically looking to add 1 new column to my calendar table. I already have the weeks numbered, but I need the "display" value now so we'd see thing slike 6/2/2018, 6/9/2018, 6/16/2018 and so on as the labels. 

1 ACCEPTED SOLUTION

Ok...so this appears to work and do what I need:

 

WeekStart

= Table.AddColumn(#"WeekStart", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))

 

WeekStart_WeekEnd

= Table.AddColumn(#"WeekStart_WeekEnd", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy") & "-" & Date.ToText(Date.EndOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))

 

 

 

I'll leave this here so the next person trying this can hopefully find it and not bang their head for a full day.


I appreciate all the help.

 

 

 

 

View solution in original post

14 REPLIES 14
Anonymous
Not applicable

Can you tell me how to correct this range ... someone it's not picking up the actual date range from column 2 

example in screenshot. 2/4/20 displays 12/14-12/20 . if I use .[date] displays 12/28/-12/31 any suggestions?

Week Selected =
VAR __day_selected =
MAXX ( ALLSELECTED ( 'Views'[Day] ), 'Views '[Day] )
VAR __start_of_week =
__day_selected - WEEKDAY ( __day_selected, 2 ) + 1
VAR __week_selected =
DATESINPERIOD ( 'Views'[Day], __start_of_week, 7, DAY )
RETURN
MINX ( __week_selected, 'Views '[Day] ) & " to " & MAXX ( __week_selected, 'Views'[Day] )
 

 

 

Anonymous
Not applicable

Hi

 

The below Dax will help to get the week start date. I am assuming that Sunday is your week start date.

 

WeekStartDate = Sheet2[Date]-  WEEKDAY(Sheet2[Date],1)+1  // Sunday as Week start date

WeekStartDate = Sheet2[Date]-  WEEKDAY(Sheet2[Date],2)+1 // Monday as Week start date

 

Weekstart Date.PNG

 

 

 

 

Hope this is what you are looking for.

 

Thansk
Raj

 

Thanking you kindly 🙂

Elegant!!

Thank you, Raj. This is the quickest and easiest solution I've found.  

Anonymous
Not applicable

Cool @Nonsensely.

Anonymous
Not applicable

Can you please help me understand how to use your DAX example?  Is it for a column or Table or Measure?   Is Sheet2 the name of the table?  and [Date] the name of the Date field in the Table?  I am unable to figure out how to get it to work.

Is there a way to do it in the Query Editor? I'm using the "Ultimate Calendar" query load and am wondering if can just be added there instead of DAX so all the Date Logic is on the calendar. We are just looking for a Sunday start yes. Is that possible do you know?

I have personally found that instead of dealing with dates in the Query Editor that it is instead preferrable to bash my head repeatedly into a brick wall until I pass out from blood loss and forget that I was trying to attempt something so foolish. But @ImkeF might be able to assist.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Haha...but if I have a nice Calendar query, I can simply copy it from one report to the next when I create them. Adding in a DAX measure would add 1 more step would it not? Not the end of the world but I'm trying to keep things simple and tidy. Maybe I'm just missing something but that's the goal anyway.

No, I absolutely get it. I'm just saying that dealing with dates in M code can be incredibly frustrating.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I'm definitely starting to feel the same way...

Ok...so this appears to work and do what I need:

 

WeekStart

= Table.AddColumn(#"WeekStart", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))

 

WeekStart_WeekEnd

= Table.AddColumn(#"WeekStart_WeekEnd", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy") & "-" & Date.ToText(Date.EndOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))

 

 

 

I'll leave this here so the next person trying this can hopefully find it and not bang their head for a full day.


I appreciate all the help.

 

 

 

 

Greg_Deckler
Super User
Super User

You should be able to use a variation of my Week Starting Quick Measure here:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Week-Starting/m-p/391487


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.