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
aryank2000
Frequent Visitor

Prior MTD calculation

Hi,

 

I need to calculate MTDs for prior year. Here is my requirement. I would need to calculate counts of measure for full month for all months in prior year and only "to date" in corresponding month. For example, If today is July 20, 2019. I would need full months for all months of 2018. But for July 2018, I would need counts upto July 19, 2018. I tried the following but, this calculates full month for all months.

 

CALCULATE(TOTALMTD('FactTable'[SalesAmount],'DimDate'[Date] ) ,SAMEPERIODLASTYEAR('DimDate'[Date]))

 

and

 

CALCULATE( FactTable[SalesAmount], SAMEPERIODLASTYEAR(DatesMTD('DimDate'[Date])))

 

But no luck. Any idea? Thank you

 

 

1 REPLY 1
Anonymous
Not applicable


 

[Your Measure] :=
var __today = today()
var __datesUpToToday =
	CALCULATETABLE(
		VALUES( DimDate[Date] ),
		DimDate[Date] <= __today,
		ALL( DimDate ) -- technically this is not necessary
	)
var __datesMtd =
	DATESMTD( DimDate[Date] )
var __intersection =
	INTERSECT(
		__datesMtd,
		__datesUpToToday
	)
var __lastYearSalesMtd =
	CALCULATE(
		SUM( 'FactTable'[SalesAmount] ),
		SAMEPERIODLASTYEAR( __intersection )
	)
return
	__lastYearSalesMtd

Best

Darek

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.