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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
v-rzhou-msft
Community Support
Community Support

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
v-rzhou-msft
Community Support
Community Support

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)

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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