Forum Discussion

aatish178's avatar
aatish178
Helper IV
2 years ago
Solved

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 Anonymous gmsamborn Anonymous Anonymous 

  • 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).

6 Replies

  • 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 ?

    • aatish178's avatar
      aatish178
      Helper IV

      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

      • lbendlin's avatar
        lbendlin
        Super User
        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?

  • 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).