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
Dayna
Helper V
Helper V

Power Query - Filter columns where the date is less than the current week

Hello,

 

I'd like to filter my source data to show me all records up to the current week, but not including the current week. I've tried adding a custom column where I create a "Today Week" by doing:

= Table.AddColumn(#"Added Custom2", "Week (Today)", each Date.WeekOfYear(DateTime.LocalNow()))

AND

= Table.AddColumn(#"Merged Columns", "Year (Today)", each Date.Year(DateTime.LocalNow()))

 

Then joining the two fields together, but I'm not seeing how I could then filter my existing year week by this?

 

Additionally, the formatting gets skewed on the week for when it's single digits - if this was the path to go down, how to I pad it with an extra leading 0 where it's a week number less than 10?

 

Many thanks for your help,

Dayna

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

Hi, @Dayna 

1.As a workaround, you might consider adding an extra column or a parameter 'Start of week' to get the start date of the current week

=Table.AddColumn(#"Added Custom", "Start of Week(Today)", each Date.StartOfWeek(DateTime.LocalNow()))

 and then filter all data with dates less than the start date of the current week.

= Table.SelectRows(#"Inserted Start of Week", each [Date] < Date.StartOfWeek(DateTime.LocalNow()))

Here you need to confirm that the data types of the columns are the same(Date/Time)

veasonfmsft_1-1656316422968.png

2.You can try Text.PadStart to format the WeekOfYear.

=Table.AddColumn(#"Inserted Week of Year1", "New week of Year", each Text.PadStart(Text.From([Week of Year], "en-US"), 2, "0"), type text)

veasonfmsft_0-1656315073235.png

 

Best Regards,
Community Support Team _ Eason

View solution in original post

2 REPLIES 2
Dayna
Helper V
Helper V

Thank you @v-easonf-msft 

v-easonf-msft
Community Support
Community Support

Hi, @Dayna 

1.As a workaround, you might consider adding an extra column or a parameter 'Start of week' to get the start date of the current week

=Table.AddColumn(#"Added Custom", "Start of Week(Today)", each Date.StartOfWeek(DateTime.LocalNow()))

 and then filter all data with dates less than the start date of the current week.

= Table.SelectRows(#"Inserted Start of Week", each [Date] < Date.StartOfWeek(DateTime.LocalNow()))

Here you need to confirm that the data types of the columns are the same(Date/Time)

veasonfmsft_1-1656316422968.png

2.You can try Text.PadStart to format the WeekOfYear.

=Table.AddColumn(#"Inserted Week of Year1", "New week of Year", each Text.PadStart(Text.From([Week of Year], "en-US"), 2, "0"), type text)

veasonfmsft_0-1656315073235.png

 

Best Regards,
Community Support Team _ Eason

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.