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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Previous Week Tuesday Date

Hi Everyone,

Is there any way to find previous week "Tuesday" date by using Power Query.
I have a requirement to filter table for every refresh & It should contains only 1 week data( Data from Tuesday to monday).
I need to create a variable and it should contains previous week "Tuesday" date, based on variable I can filter the table.

 

Thanks in advance

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please add the "Filter Row" step in my M code to yours.

...
#"Filtered Rows" = 
    let _WeekStart = Date.AddDays(Date.StartOfWeek(Date.From(DateTime.FixedLocalNow()), 2),-Date.DayOfWeek(Date.From(DateTime.FixedLocalNow()), Day.Tuesday)),
        _WeekEnd = Date.AddDays(_WeekStart,6)
    in
    Table.SelectRows(#"Changed Type", each [Date] >= _WeekStart and [Date] <= _WeekEnd)
...

The step above "Filter Row" step names #"Change Type", please change the step name as your before step name.

The whole M code.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc67DcAwDAPRXVgLsCT/ZzG8/xohUoVIea+6c5CeWcKLBwzhuPaxpHWlShpKjbSUOqkqDdJUmqSttEhNaf/HmIZUev9x7wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}}),
    #"Filtered Rows" = 
    let _WeekStart = Date.AddDays(Date.StartOfWeek(Date.From(DateTime.FixedLocalNow()), 2),-Date.DayOfWeek(Date.From(DateTime.FixedLocalNow()), Day.Tuesday)),
        _WeekEnd = Date.AddDays(_WeekStart,6)
    in
    Table.SelectRows(#"Changed Type", each [Date] >= _WeekStart and [Date] <= _WeekEnd)
in
    #"Filtered Rows"

My Sample:

RicoZhou_0-1665481776183.png

After filter my table will only show data from 2022/10/11 to 2022/10/17 until next Tuesday 2022/10/18.

Result is as below.

RicoZhou_1-1665481845754.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

Please add the "Filter Row" step in my M code to yours.

...
#"Filtered Rows" = 
    let _WeekStart = Date.AddDays(Date.StartOfWeek(Date.From(DateTime.FixedLocalNow()), 2),-Date.DayOfWeek(Date.From(DateTime.FixedLocalNow()), Day.Tuesday)),
        _WeekEnd = Date.AddDays(_WeekStart,6)
    in
    Table.SelectRows(#"Changed Type", each [Date] >= _WeekStart and [Date] <= _WeekEnd)
...

The step above "Filter Row" step names #"Change Type", please change the step name as your before step name.

The whole M code.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc67DcAwDAPRXVgLsCT/ZzG8/xohUoVIea+6c5CeWcKLBwzhuPaxpHWlShpKjbSUOqkqDdJUmqSttEhNaf/HmIZUev9x7wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}}),
    #"Filtered Rows" = 
    let _WeekStart = Date.AddDays(Date.StartOfWeek(Date.From(DateTime.FixedLocalNow()), 2),-Date.DayOfWeek(Date.From(DateTime.FixedLocalNow()), Day.Tuesday)),
        _WeekEnd = Date.AddDays(_WeekStart,6)
    in
    Table.SelectRows(#"Changed Type", each [Date] >= _WeekStart and [Date] <= _WeekEnd)
in
    #"Filtered Rows"

My Sample:

RicoZhou_0-1665481776183.png

After filter my table will only show data from 2022/10/11 to 2022/10/17 until next Tuesday 2022/10/18.

Result is as below.

RicoZhou_1-1665481845754.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Anonymous , if you need based on today , these two dates can help

Date.AddDays(Date.StartOfWeek(Date.From(DateTime.FixedLocalNow()), 2),-7)

 

 

Date.StartOfWeek(Date.From(DateTime.FixedLocalNow()), 1)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

Last Tuesday = Date.AddDays(Date.StartOfWeek([Date], 2),-7)

This Tuesday = Date.StartOfWeek([Date], 2)

Next Tuesday = Date.AddDays(Date.StartOfWeek([Date], 2),7)

 

for today use Date.From(DateTime.FixedLocalNow()), in place of date column

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.