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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Valerie78
New Member

datediff between two columns, with a filter applicable

I have the following data:

 

Name

Weekly hours

Start Date

End Date

Weeks worked

Hours due to work

Theresa May

37

06/04/2020

 

39

1443

Boris Johnson

22

01/06/2020

31/07/2020

9

198

Keir Starmer

40

01/04/2020

 

39

1443

 

 

Formulas:

 

weeks worked = DATEDIFF([Start Date],IF[End Date],[End Date],TODAY()),WEEK)

hours due to work = CALCULATE(SUM([weeks worked])*SUM([Weekly Hours]))

 

I am keen for the “Hours due to work” to work on a date filter too, so if I want to know how many hours An or Keir were meant to work let’s say in the month of December, it would show up as 4 weeks worked with 37 hours each week = 148 hours

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Valerie78  ,

Here are the steps you can follow:

1. Create a calendar table

Date = CALENDARAUTO()

2. Create measure.

weeks worked =
var _startdate=MIN('Date'[Date])
var _enddate=MAX('Date'[Date])
return
DATEDIFF(_startdate,_enddate,WEEK)
hours due to work = CALCULATE([weeks worked]*SUM([Weekly Hours]))

3. Put the date of the calendar table into the slicer

4. Result.

v-yangliu-msft_0-1610068782869.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @Valerie78  ,

Here are the steps you can follow:

1. Create a calendar table

Date = CALENDARAUTO()

2. Create measure.

weeks worked =
var _startdate=MIN('Date'[Date])
var _enddate=MAX('Date'[Date])
return
DATEDIFF(_startdate,_enddate,WEEK)
hours due to work = CALCULATE([weeks worked]*SUM([Weekly Hours]))

3. Put the date of the calendar table into the slicer

4. Result.

v-yangliu-msft_0-1610068782869.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

@Valerie78 , Try measures like

 

measure =
sumx(Table, Datediff([Start Date], coalesce([End Date], today()), Week) * [Weekly hours])

 

or based on selected date

measure =
var _max = maxx(allselected('Date'), 'Date'[Date])
return
sumx(Table, Datediff([Start Date], coalesce([End Date], _max), Week) * [Weekly hours])

 

Better to have daily rate and multiple it by workdays

lbendlin
Super User
Super User

- what is a week, which day does it start, which day does it end, is it mapped to years, quarters or months in any way?

- do you plan to exclude weekends and holidays?  If so, which days are weekend? Which regional holidays do you want to consider?

- can "weekly hours" safely be broken down into "daily hours"  or do you have special provisions like half days , bridge days etc?

 

Your best bet is to have a fully formed calendar table that clearly indicates which days are working days (better yet indicate the working hours for each day.

 

It's the weekend! Or is it? - Microsoft Power BI Community

Hi 

 

I do have a seperate calendar table which is managed with a relationship connection that shows working days vs non working days.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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