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
Anonymous
Not applicable

Help please - datesinperiod question

Hi,

 

I have this formula:

 

Test = CALCULATE(average(Rental_Net), DATESINPERIOD('Date'[Date], max('Date'[Date]),-12,MONTH))
 
I want to be able to change the constant 12 to a formula depending on the date I selected on the date slicer from calendar table. The problem is when I select 9 calendar months for example:
 
jdalfonso_0-1630306085382.png

it still gets the average for the last 12 because of the constant 12. Is there a way to "macro" the 12? Thanks! 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , if you selecting a date range from the slicer and you need that much data. you do not need datesinperiod

 

CALCULATE(average(Rental_Net)) , should do if date table is joined.

 

If you want a dynamic number in place of 12, use what if parameter  https://docs.microsoft.com/en-us/power-bi/desktop-what-if

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

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , if you selecting a date range from the slicer and you need that much data. you do not need datesinperiod

 

CALCULATE(average(Rental_Net)) , should do if date table is joined.

 

If you want a dynamic number in place of 12, use what if parameter  https://docs.microsoft.com/en-us/power-bi/desktop-what-if

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.