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

Total No of Days Spent month wise breakup using Time periods

Hi All,

I'm a newbee. I have a situation where i need to calculate the total no. of days spent on each task on monthly basis.
I have time periods in a slicer with values "Current Month", "Prev Month", "Last 3 Months", "Next Month" & Next 3 Months"

Based on the time period selected, i want to show the total no of days spent on a task.

Note: My Date Table is built on Start Date.

 

srinirayreach03_0-1632977193892.png

 

It will be really helpful with a sample code snippet or any link.

 

Thanks in Advance

Srinivas K

3 REPLIES 3
Anonymous
Not applicable

Hi @amitchandak 
Thanks alot for your response. But if you please go thru the post again, you will come to know my exact need.
if u see, task2 in the screenshot, it starts on  Sep-03-201 & ends on Oct -03 where total days will be 30 days. but, When i select time period as Current Month, it should calculate total days from start date to month end of current month and the remaining days (2Days)should be covered under next month i.e. Oct. 

 

srinirayreach03_0-1632984728380.png

 

Thanks ,

Srinivas K

 
 
amitchandak
Super User
Super User

@Anonymous , Try measures like

 

This Month=
var _min1 = eomonth(today(),-1)+1
var _max1 = eomonth(today(),0)
var _min = if(min([Task Start Date]) >= _min1, min([Start Date]) , _min1)
var _min = if(Max([Task End Date]) <= _max1, Max([Task End Date]) , _max1)
return
datediff(_min,_max, Day)

 

Last Month=
var _min1 = eomonth(today(),-2)+1
var _max1 = eomonth(today(),-1)
var _min = if(min([Task Start Date]) >= _min1, min([Start Date]) , _min1)
var _min = if(Max([Task End Date]) <= _max1, Max([Task End Date]) , _max1)
return
datediff(_min,_max, Day)

 

Last 3 Month= // Use -4 , -1 in place of -3 and 0 if needed
var _min1 = eomonth(today(),-3)+1
var _max1 = eomonth(today(),0)
var _min = if(min([Task Start Date]) >= _min1, min([Start Date]) , _min1)
var _min = if(Max([Task End Date]) <= _max1, Max([Task End Date]) , _max1)
return
datediff(_min,_max, 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
Anonymous
Not applicable

Please ignore the 2nd Image and consider this

srinirayreach03_0-1632988650098.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.