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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
RiniMaria
Frequent Visitor

Date Filter

Hello,

 

I have a table which has information always for the last 12months (rolling months). This table is refreshed every month.

I need to be able to filter this table two ways in Power Query  -

1. Always take the oldest 3 months

2. Always take the latest 3 months.

 

 

1 ACCEPTED SOLUTION

 

That's perfect, thanks.

I'd add a relative month column to your data in Power Query, something like this:

RelativeMonth =
( Date.Year([Time]) * 12 + Date.Month([Time]) )
- ( Date.Year(DateTime.LocalNow()) * 12 + Date.Month(DateTime.LocalNow()) )

 

This should give you a column that contains the values -1 to -12 which can then be easily used in either M or DAX to grab any month you want. For example:

// EarliestThreeMonths_M
List.Contains({-12, -11, -10}, [RelativeMonth])

// EarliestThreeMonths_DAX
YourTable[RelativeMonth] IN {-12, -11, -10}

// LatestThreeMonths_M_DAX
[RelativeMonth] >= -3

// MiddleFourMonths_M
List.Contains({-5, -6, -7, -8}, [RelativeMonth])
// or
[RelativeMonth] >= -8 and [RelativeMonth] <= -5

// and so on...

 

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

4 REPLIES 4
RiniMaria
Frequent Visitor

Thank you so much! This works!

RiniMaria
Frequent Visitor

Hi @BA_Pete,

 

My date column is in Date format (YYYY-MM-DD). Data is connected to different regions so the dates will be repeated and I have 1000+ rows of data in here. Here is a snippet - 

RiniMaria_0-1665580636829.png

Not sure if this answers you question. Let me know!

 

That's perfect, thanks.

I'd add a relative month column to your data in Power Query, something like this:

RelativeMonth =
( Date.Year([Time]) * 12 + Date.Month([Time]) )
- ( Date.Year(DateTime.LocalNow()) * 12 + Date.Month(DateTime.LocalNow()) )

 

This should give you a column that contains the values -1 to -12 which can then be easily used in either M or DAX to grab any month you want. For example:

// EarliestThreeMonths_M
List.Contains({-12, -11, -10}, [RelativeMonth])

// EarliestThreeMonths_DAX
YourTable[RelativeMonth] IN {-12, -11, -10}

// LatestThreeMonths_M_DAX
[RelativeMonth] >= -3

// MiddleFourMonths_M
List.Contains({-5, -6, -7, -8}, [RelativeMonth])
// or
[RelativeMonth] >= -8 and [RelativeMonth] <= -5

// and so on...

 

Pete



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

Proud to be a Datanaut!




BA_Pete
Super User
Super User

Hi @RiniMaria ,

 

Can you provide a small example of what your data looks like please?

The main thing I need to see is the date format and frequency in your table i.e. are they all individual dates, month-end dates, or something else.

 

Pete



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

Proud to be a Datanaut!




Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.