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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Aahil10
Frequent Visitor

Filter MTD Query with custom date range

Hello!

I have used the TOTALMTD and DATESMTD function in my measures but now need to figure out how to filter it to a custom date range for each month. The month's we use dont exactly follow the Calendar month - e.g May starts on Mya 1 but ends June 6. Every month is slightly different too.

The formula is currently as follows:

 

MTD = TOTALMTD('Core Measures'[Variance],SouthDATA[Production Date])
 
Is there any way to filter one more level using Production Month, using the same functions, or do I have to create new ones?
 
Thanks!
2 REPLIES 2
Anonymous
Not applicable

Hi @Aahil10,

Time intelligence functions not suitable for custom date ranges or field calculations, they are based on the auto-generated hidden calendar.

Auto date/time in Power BI Desktop - Power BI | Microsoft Docs

In my opinion, I'd like to suggest you use the date function manually to filter the custom date range and add the custom field as filter conditions.

If you are confused about the coding formula, please share some dummy data to test.

How to Get Your Question Answered Quickly
Regards,

Xiaoxin Sheng

amitchandak
Super User
Super User

@Aahil10 , I such case base on start date of period and end date of period create following columns in your date table

 

Period Rank = RANKX(all('Period'),'Period'[year period],,ASC,Dense) 

//OR

Period Rank = RANKX(all('Period'),'Period'[period start date],,ASC,Dense) 

Period Day = DATEDIFF('Date'[Period Start Date],'Date'[Date],Day)+1


This Period = CALCULATE(sum('order'[Qty]), FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])))
Last Period = CALCULATE(sum('order'[Qty]), FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])-1))

 

PTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Period Rank]=max('Date'[Period Rank]) && [Period Day] <=max([Period Day])))
LPTD = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Period Rank]=max('Date'[Period Rank])-1 && [Period Day] <=max([Period Day])))

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.