Forum Discussion
Sum if value is between two dates
Hi,
I want to calculate the hours for each employee on each day (and sum these per period).
First I need to check the Schedule ID per Employee ID on each day, because this can change over time (as you can see below in Schedule table for Employee ID 59).
Then I need to calculate the correct hours belonging to the correct Schedule ID on a particular date for each Employee ID. This probably by checking if the date in my Hours table is between from date and to date in my Schedule table.
I would like to do this in a measure where the result for Employee ID 2 should be 5*8hours=40hours. And the result for Employee ID 59 should be 3*8hours=24hours. By filtering on the Date table the results should be recalculated as a measure does.
Can anyone help me with this measure formula?
There are 3 tables as below:
Schedule table:
Hours table:
Date table (calendar table, with every date):
JC2022
Please try= SUMX ( Schedule, SUMX ( FILTER ( Hours, Hours[Schedule ID] = Schedule[Schedule ID] && Hours[Date] >= Schedule[From Date] && Hours[Date] <= Schedule[To Date] ), Schedule[Hours] ) )