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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
allieg2830
New Member

Calculation for Calendar To-Date Prior Period

Hi! I am trying to calculate the value for the prior period in the following scenario:

 

The primary date range (CYTD): Jan 2 2022 - June 18 2022 

The previous time period range: Jul 18 2021 - Jan 1 2022

 

How would I calculate a value (e.g., Total Traffic) for the previous time period? I would like the calculation to be dynamic depending on where in the year I am (e.g., adaptable for the primary period selection of Jan 2 2022 - Dec 1 2022). 

 

I do have a date table with the following columns: Year (YYYY), Week No (1-52), Date (DD/MM/YYYY), SundayEnding, (DD/MM/YYYY), MonthNo (1-12), MonthName (e.g., Dec, Jan), Days in Month, etc.)

 

Thanks for any help in advance!

 

 

 

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @allieg2830 

 

Can you provide some sample data or simple pbix files? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures.

 

Best Regards,

Community Support Team _Charlotte

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

@allieg2830 ,

 

YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+2
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LYTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())

var _min =  date(Year(_max1) -1, month(_max1) , Day(_max1))
var _max= eomonth(_max,-1*MONTH(_max))
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

or

 

same period based on date range
Last Period =
var _max =maxx(allseleceted(date),date[date])
var _min =maxx(allseleceted(date),date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.