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
DonalMc
Advocate II
Advocate II

Sort column for Week Period Spanning the Year

I have added a column to my Power Query date table called Week Dates, as below, to get a result like "Jan-25-2010 to Jan-31-2010"

Week Dates =

Date.ToText( Date.StartOfWeek([Date],firstDayofWeek), "MMM-dd-yyyy")&" to "& Date.ToText(Date.EndOfWeek([Date],firstDayofWeek), "MMM-dd-yyyy")

 

I am unable to create a sort column for this column because the column spans the year, and I get the we can't sort by this column because there can't be more than one value message - you can see the problem below.

 

DonalMc_0-1683818061912.png

I think the best approach is to limit the Week Dates column to a periond that does not span the year - any suggestions as to how I would do this, or any other suggestions as to the sort column?

Thanks

1 ACCEPTED SOLUTION
DonalMc
Advocate II
Advocate II

Got this sorted, see below for anyone else trying to achieve same

 

First Weekday Year = 

if Date.StartOfWeek([Date],firstDayofWeek) <= Date.StartOfYear([Date]) then Date.StartOfYear([Date]) else Date.StartOfWeek([Date],firstDayofWeek)

 

Last Weekday Year = 

if Date.EndOfWeek([Date],firstDayofWeek) >= Date.EndOfYear([Date]) then Date.EndOfYear([Date]) else Date.EndOfWeek([Date],firstDayofWeek)

 

Week Dates =

Date.ToText([First Weekday Year], "MMM-dd-yy")&" to "& Date.ToText([Last Weekday Year], "MMM-dd-yy")

View solution in original post

1 REPLY 1
DonalMc
Advocate II
Advocate II

Got this sorted, see below for anyone else trying to achieve same

 

First Weekday Year = 

if Date.StartOfWeek([Date],firstDayofWeek) <= Date.StartOfYear([Date]) then Date.StartOfYear([Date]) else Date.StartOfWeek([Date],firstDayofWeek)

 

Last Weekday Year = 

if Date.EndOfWeek([Date],firstDayofWeek) >= Date.EndOfYear([Date]) then Date.EndOfYear([Date]) else Date.EndOfWeek([Date],firstDayofWeek)

 

Week Dates =

Date.ToText([First Weekday Year], "MMM-dd-yy")&" to "& Date.ToText([Last Weekday Year], "MMM-dd-yy")

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.

Top Solution Authors
Top Kudoed Authors