Power Query to Dynamically Filter By Current Year and Beyond

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,171
Office Version
  1. 365
Platform
  1. Windows
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.

YearData
2018Table [Not Yet Expanded]
2019Table [Not Yet Expanded]
2020Table [Not Yet Expanded]
2021Table [Not Yet Expanded]
2022Table [Not Yet Expanded]
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
maybe adapt
Power Query:
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
YearYear
20182020
20192021
20202022
2021
2022


update your profile about Excel version and OS
 
Last edited:
Upvote 0
Exactly what Ineeded - custom column with Date.Year(DateTime.LocalNow())

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top