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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
aatish178
Helper IV
Helper IV

Filtering date column data in power query

Hi All,

I want to filter a date column to only show last 3 years of data from today's date in power query. The filtering should be from today's date and it would be dynamic after every day.

Can you please help me to load only last 3 years of data using filtering through power query code

@amitchandak @v-huijiey-msft @gmsamborn @v-kaiyue-msft @v-jialongy-msft 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

I don't think you can do that in Power Query. I believe you will need to load the entire data set, and then filter.  M-code would be something like:

Table.SelectRows(#"Previous Step", each [date_column_to_filter_on] > Date.AddYears(Date.From(DateTime.FixedLocalNow()),-3))

If you only want to LOAD the past three years, that would need to be done either at the data source, or, depending on the data source, perhaps in your connector (eg if it involves an api perhaps there is an argument to restrict the data).

View solution in original post

6 REPLIES 6
ronrsnfld
Super User
Super User

I don't think you can do that in Power Query. I believe you will need to load the entire data set, and then filter.  M-code would be something like:

Table.SelectRows(#"Previous Step", each [date_column_to_filter_on] > Date.AddYears(Date.From(DateTime.FixedLocalNow()),-3))

If you only want to LOAD the past three years, that would need to be done either at the data source, or, depending on the data source, perhaps in your connector (eg if it involves an api perhaps there is an argument to restrict the data).

lbendlin
Super User
Super User

last 3 years of data from today's date

full years or sliding window?  Assuming today is 2024-07-01, what would be the minimum date you wanted to pull? 2021-07-02 ?

Hi, thanks for the reply... 

I want to load only last 3 years of data from today's date 

So basically it would be like Date>=last 3 years of date from today

I want to load only last 3 years of data from today's date 

So basically it would be like Date>=last 3 years of date from today

That's still ambiguous. Including or excluding "today"  from three years back?

Let's say today is July 3rd then I want to load last 3 years of data from today that is 3rd July 2021 onwards.

 

If today's date is 5th July 2024 then power bi should load data from 5th July 2021 onwards

 

If today's date is 10th july, then power bi should load data from 10th july 2021 onwards

 

The date field has historical data till 1974, I only want to filter it based on last 3 years from today's date.

I want to make it dynamic in power query itself. 

Plz help me if there is any possible solution using power query language code 

 

Let's say today is July 3rd then I want to load last 3 years of data from today that is 3rd July 2021 onwards.

 

That is not "the last 3 years". That is "the last three years plus one day".  Are you sure you want that?

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.