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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
johnpjustus
Helper IV
Helper IV

Restrict records to current year

Hi,

I am creating a dataflow from spread sheet in sharepoint using webapi connector.

 

  Source = Excel.Workbook(Web.Contents("https://test.sharepoint.com/sites/ORT-Shared%20Documents/Training/GSAA.xlsx"), null, true),
  #"Navigation 1" = Source{[Item = "IBG", Kind = "Sheet"]}[Data],
 
This spread sheet has few fields with lot of records. The date field has values all the way from 2001. I want to restrict values to current year.
How can I achieve that so I don't bring all the records back from 2001 to Power Query online, so that the dataset that I create using this data flow contains only current year data
Thanks,
John
4 REPLIES 4
collinsg
Super User
Super User

Hi John,

Adding this line of M code will filter for records in the current year.

= Table.SelectRows(#"Previous Step", each Date.IsInCurrentYear([Date]))
  •  For "Previous Step" substitute the name of your previous step.
  • For [Date] substitute the name of your date column.

To add a line of M code, select the step after which you want to filter and press "fx" beside the formula bar.

2023-06-20_22-17-57.jpg

 

 

 

Hope this helps.

Thank you so much and it worked when I followed the steps you outlined.

So I believe in doing so whenever the dataflow is scgeduled to run, it sends only the current year query to source correct?

Thanks,

John

 

 

Hello John,

I will have to be careful with my answer because when you say "sends only...query to source" the precise answer, in general, depends on whether query folding occurs. However the precise answer may not matter to you if you're only interested in the "bottom line" result - i.e. will the query return records for the current year...the answer is "yes".

To go back to the precise answer, some sources, such as SqlServer can carry out filtering before returning a result. If this is the case Power Query will delegate filtering to the source and send a query to the source asking it to return filtered results.

 

If a source cannot carry out filtering (e.g. an Excel file), Power Query will fetch and scan the source line by line to do the filtering. In this case the query is not "sent" but the result is still filtered.

 

You can read more about query folding here.

Hope this helps.

 

Thank you so much for the information, really helpful.

One last thing to check. Say I have the following file:

Now using the M-language I filtered for current year which is 2023. If I do filtering (Filter rows from the UI) for 2023 instead of M-language, the process is same correct?

 

And I understand the query folding. In this case, Power BI brings all the data to memory and then filters the data for 2023.

 

LocIDLocationDateAgeGrpPopMalePopFemalePopTotal
5Antigua and Barbuda1/4/20150-43.5433.4366.979
6Argentina1/5/20220-41836.1871769.8163606.003
7Armenia1/6/20230-4107.36893.715201.083
8Aruba1/7/20230-43.4023.2576.659
9Australia1/8/20230-4750.45711.4351461.885
10Austria1/9/20230-4200.53190.404390.934
11Afghanistan1/10/20230-42715.072600.5355315.605
12Albania1/11/20230-492.62281.239173.861
13Algeria1/12/20230-41966.4151885.8693852.284
14Angola1/13/20230-42233.0412239.0354472.076
15Antigua and Barbuda1/14/20230-43.5433.4366.979
16Argentina1/15/20230-41836.1871769.8163606.003
17Armenia1/16/20230-4107.36893.715201.083
18Aruba1/17/20230-43.4023.2576.659
19Australia1/18/20230-4750.45711.4351461.885
20Austria1/19/20230-4200.53190.404390.934
      

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.