Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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?
Solved! Go to Solution.
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
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
Thanks so much!
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
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