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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Laveigo1
New Member

Power Query Editor Date Filter 2 quarters prior but not the prior quarter

Hi

 

I am trying to filter my data to only show data from 2 quarters prior from today (e.g. April to June) but not the prior quarter's data (July to September). Is there a way to do so? At the moment, I can see that there is a filter for "Prior Quarter" and "Date.IsInPreviousNQuarters".

 

= Table.SelectRows(#"xxx", each Date.IsInPreviousNQuarters([date],2)) allows me to filter the data from April to September, but I do not want to include the prior quarter data (July to September). I would like to do this dynamically, so that come next quarter, the prior quarter and 2 quarter prior will adjust automatically. Does anyone know how to do so? Your help is much appreciated. 

 

Thanks

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Laveigo1 ,

 

You can try using your current filter, but also excluding the prior quarter at the same time, something like this:

Table.SelectRows(
    PreviousStepName,
    each Date.IsInPreviousNQuarters([date], 2)
        and not Date.IsInPreviousNQuarters([date], 1)
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Laveigo1 ,

Thanks for all the replies!
And @Laveigo1 , here is my sample data:

vjunyantmsft_0-1731894856315.png

You can try this M code:

let
    Source = Table.FromRecords({
        [Date=#date(2024,11,30), Value=11],
        [Date=#date(2024,10,31), Value=10],
        [Date=#date(2024,9,30), Value=9],
        [Date=#date(2024,8,31), Value=8],
        [Date=#date(2024,7,31), Value=7],
        [Date=#date(2024,6,30), Value=6],
        [Date=#date(2024,5,31), Value=5],
        [Date=#date(2024,4,30), Value=4],
        [Date=#date(2024,3,31), Value=3],
        [Date=#date(2024,2,29), Value=2],
        [Date=#date(2024,1,31), Value=1]
    }),
    CurrentDate = DateTime.LocalNow(),
    PreviousQuarterStart = Date.From(Date.AddQuarters(Date.StartOfQuarter(CurrentDate), -1)),
    PreviousQuarterEnd = Date.From(Date.EndOfQuarter(PreviousQuarterStart)),
    PreviousTwoQuartersStart = Date.From(Date.AddQuarters(Date.StartOfQuarter(CurrentDate), -2)),
    PreviousTwoQuartersEnd = Date.From(Date.EndOfQuarter(PreviousTwoQuartersStart)),
    FilteredData = Table.SelectRows(Source, each Date.From([Date]) >= PreviousTwoQuartersStart and Date.From([Date]) <= PreviousTwoQuartersEnd and Date.From([Date]) < PreviousQuarterStart)
in
    FilteredData

And the final output is as below:

vjunyantmsft_1-1731894913186.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Omid_Motamedise
Super User
Super User

you can add another condition and neglect value in the previous quarter by rewriting your formula as:

 

= Table.SelectRows(#"xxx", each Date.IsInPreviousNQuarters([date],2) and not Date.IsInPreviousNQuarters([date],1))

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
BA_Pete
Super User
Super User

Hi @Laveigo1 ,

 

You can try using your current filter, but also excluding the prior quarter at the same time, something like this:

Table.SelectRows(
    PreviousStepName,
    each Date.IsInPreviousNQuarters([date], 2)
        and not Date.IsInPreviousNQuarters([date], 1)
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors