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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lucy_wilshaw
New Member

Rolling Date Measure for Power BI

Hi,

 

I would like to set up a new date measure in Power BI desktop using the DAX code. I currently have it set up to "Date = CALENDAR (DATE(2012,1,1), DATE(2020,12,31))" but would like to change it so it captures the latest 10 years data as I refresh the data. So I would ideally like to use a DAX code that calls data "from a specified date to a couple of months after view date" or the "latest 120 months of data from a specified date". I had a look at the DAX code list and thought EDATE or EOMONTH would do the job but I couldn't get them to work, I am afraid.

 

Many thanks for your help.

 

Best wishes,

 

Lucy

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @lucy_wilshaw ,

 

I think you want to filter out the data of recent months from a starting date, the starting date and the number of months are both selected by the slicer.

 

Sample data

vstephenmsft_4-1642398398903.png

 

Here's my solution.

1.Create a calendar table.

 

Date = CALENDAR (DATE(2012,1,1), DATE(2020,12,31))

 

 There's no relationship between the calendar table and the main table.

vstephenmsft_0-1642388892159.png

 

2.Create a what-if parameter, set maximum is 120.

vstephenmsft_1-1642397995951.png

vstephenmsft_2-1642398300557.png

 

 

 

3.Create a measure. Put it into the page level visual and set show items when the value is 1.

Measure = var _start=SELECTEDVALUE('Date'[Date])
var _num=SELECTEDVALUE('Parameter'[Parameter])
return IF(MAX('Table'[Date])>=_start&&MAX('Table'[Date])<=EOMONTH(_start,_num-1),1)

vstephenmsft_0-1642397939171.png

 

Now you can filter date and month number.

vstephenmsft_3-1642398373817.png

 

 

Best Regards,

Stephen Tao

 

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @lucy_wilshaw ,

 

I think you want to filter out the data of recent months from a starting date, the starting date and the number of months are both selected by the slicer.

 

Sample data

vstephenmsft_4-1642398398903.png

 

Here's my solution.

1.Create a calendar table.

 

Date = CALENDAR (DATE(2012,1,1), DATE(2020,12,31))

 

 There's no relationship between the calendar table and the main table.

vstephenmsft_0-1642388892159.png

 

2.Create a what-if parameter, set maximum is 120.

vstephenmsft_1-1642397995951.png

vstephenmsft_2-1642398300557.png

 

 

 

3.Create a measure. Put it into the page level visual and set show items when the value is 1.

Measure = var _start=SELECTEDVALUE('Date'[Date])
var _num=SELECTEDVALUE('Parameter'[Parameter])
return IF(MAX('Table'[Date])>=_start&&MAX('Table'[Date])<=EOMONTH(_start,_num-1),1)

vstephenmsft_0-1642397939171.png

 

Now you can filter date and month number.

vstephenmsft_3-1642398373817.png

 

 

Best Regards,

Stephen Tao

 

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

amitchandak
Super User
Super User

@lucy_wilshaw , Try like

Date =
var _end = date(year(today()),12,31)
var _st = date(year(today())-10,1,1)
return
calendar(_st,_end)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.