# Power Query to Dynamically Filter By Current Year and Beyond



## legalhustler (Dec 28, 2020)

I am scraping a web page with a list of holidays with Power Query.  The web page has a list of current and prior year holidays.  I want to *dynamically *filter out prior years based on the current year we are in.  I want to also keep future years.  So in the table below I want filter out 2018 and 2019 (since we're in 2020) and show  only 2020, 2021 and 2022.  I don't want to click the filter drop down and simply remove prior years, but need a dynamic way (IF statement to check if we're in current year?) because this something that needs to happen every year.


YearData2018Table [Not Yet Expanded]2019Table [Not Yet Expanded]2020Table [Not Yet Expanded]2021Table [Not Yet Expanded]2022Table [Not Yet Expanded]


----------



## sandy666 (Dec 28, 2020)

maybe adapt

```
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Condition = Table.AddColumn(Source, "Condition", each [Year] >= Date.Year(DateTime.LocalNow())),
    True = Table.SelectRows(Condition, each ([Condition] = true)),
    RC = Table.RemoveColumns(True,{"Condition"})
in
    RC
```
YearYear20182020201920212020202220212022

*update your profile about Excel version and OS*


----------



## legalhustler (Dec 29, 2020)

Exactly what Ineeded - custom column with Date.Year(DateTime.LocalNow())

Thanks!


----------



## sandy666 (Dec 29, 2020)

You are welcome
and
*update your profile about Excel version and OS*


----------



## legalhustler (Dec 29, 2020)

sandy666 said:


> You are welcome
> and
> *update your profile about Excel version and OS*


Thanks - just updated


----------



## sandy666 (Dec 29, 2020)

Thanks for updating
Have a nice day


----------

