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
Syndicate_Admin
Administrator
Administrator

Filter Power Query last 60 days

Can anybody help me?
I need to create a filter on Power Query with the last 60 days, considering the current date. Thanks.

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

Hi @Syndicate_Admin ,

According to your description, here's my solution. Add a new step in Advanced editor.

Table.SelectRows(#"Changed Type", each Duration.Days(Date.From(DateTime.LocalNow())-[Date])<=60)

 Here's the whole code of my sample.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI31DdUitWBcoyQOcbIHBNkjikyxwyZY47MsUDmWII4sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"New"=Table.SelectRows(#"Changed Type", each Duration.Days(Date.From(DateTime.LocalNow())-[Date])<=60)
in
    #"New"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

According to your description, here's my solution. Add a new step in Advanced editor.

Table.SelectRows(#"Changed Type", each Duration.Days(Date.From(DateTime.LocalNow())-[Date])<=60)

 Here's the whole code of my sample.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI31DdUitWBcoyQOcbIHBNkjikyxwyZY47MsUDmWII4sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"New"=Table.SelectRows(#"Changed Type", each Duration.Days(Date.From(DateTime.LocalNow())-[Date])<=60)
in
    #"New"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

Vijay_A_Verma
Super User
Super User

You can use Date.IsInPreviousNDays

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

if you want to remove records > 60 days

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TchLCoAwDAXAu2TdB0nUti796xlK738NoYGQWU5rtFEiZVVwhWbqqdEeiq0OrwIpo06vDLW6QrHV7bVA6qjHa4ZavaHY6vOaICv1/gM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Date", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each Date.IsInPreviousNDays([Date], 60))
in
    #"Filtered Rows"

 If you want to remove records <60 days

then just put not

Table.SelectRows(#"Changed Type", each not Date.IsInPreviousNDays([Date], 60))

 👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)

How to get your questions answered quickly  -- How to provide sample data

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