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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
IamTDR
Responsive Resident
Responsive Resident

Power Query: Filter a Date Field by Current and Prior Fiscal Year (Keeping Query Native)

Hi

I have a massive table that has a single Date field.  I am interested in applying a step in power query to filter this table by the current fiscal year and the prior fiscal year.  My company's fiscal year begins on May 1 and ends April 30th.  Ideally I'm hoping this step would be able to keep the query native to maintain performance.
Is this possible?

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @IamTDR ,
you are absolutely correct - sorry, didn't think about that.

You can adjust like so:

if Date.Month(Date.From(DateTime.LocalNow())) < 5 then #date(Date.Year(Date.From(DateTime.LocalNow())) - 2, 5, 1) else #date(Date.Year(Date.From(DateTime.LocalNow())) - 1, 5, 1)

and

if Date.Month(Date.From(DateTime.LocalNow())) < 5 then #date(Date.Year(Date.From(DateTime.LocalNow())) , 4, 30) else #date(Date.Year(Date.From(DateTime.LocalNow())) + 1, 4, 30)

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Super User
Super User

Hi @IamTDR ,
you are absolutely correct - sorry, didn't think about that.

You can adjust like so:

if Date.Month(Date.From(DateTime.LocalNow())) < 5 then #date(Date.Year(Date.From(DateTime.LocalNow())) - 2, 5, 1) else #date(Date.Year(Date.From(DateTime.LocalNow())) - 1, 5, 1)

and

if Date.Month(Date.From(DateTime.LocalNow())) < 5 then #date(Date.Year(Date.From(DateTime.LocalNow())) , 4, 30) else #date(Date.Year(Date.From(DateTime.LocalNow())) + 1, 4, 30)

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

IamTDR
Responsive Resident
Responsive Resident

Thanks so much!

ImkeF
Super User
Super User

Hi @IamTDR ,
the dynamic start parameter can be written like so: 

#date(Date.Year(Date.From(DateTime.LocalNow())) - 1,5,1)

and the end-parameter like so:

#date(Date.Year(Date.From(DateTime.LocalNow())) + 1,4,30)

Just filter your table using the UI by dummy-values and replace the fixed dates by the expressions above.
Query folding should still work.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

IamTDR
Responsive Resident
Responsive Resident

Thank you. I was able to get this to work and maintain query folding.
Will this still work say come January 2023??  If my fiscal year is May - April, come this Jan23, wouldnt this make my results be 5/1/22 - 4/30/24 ???  In which case that would not be correct. May 2022 through April 2023 results should be 5/1/21 - 4/30/23

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors