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
Syndicate_Admin
Administrator
Administrator

Calculate days worked according to a filter

Hello

I have a Fact with employees with their period start date and end period date, and I need to calculate according to a date filter of a calendar dimension. How many days I work in the range of dates selected by the user. For example.

consultation period1-9-2215-9-22
Septiempre
IncomeRetreat123456789101112131415days x enteredx days withdrawn
Person 19-9-22 1111111111111114
Person 215-01-2212-09-22111111111111 12
Person 36-9-2212-9-22 111111 6
Total1418

I have the following metric.

Days Worked =
Where _MinDate =
MIN( 'Calendar.HHRR Dates'[Date] )
Where _MaxDate =
.MAX( 'Calendar.HHRR Dates'[Date] )
Where _ResultDateMax=
CALCULATE(
.MAX('HHRR Movements'[End_Date_Period]),
'HHRR Movements'[Active]=TRUE
,'HHRR Movements'[End_Date_Period] >= _MinDate
,'HHRR Movements'[End_Date_Period] <= _MaxDate
)

Where Result =
DATEDIFF(_MinDate,_ResultDateMax,DAY)+1
Return
Result
Ldanielj28_1-1665709610973.png


But I should mark from the 6 that I enter until the 12 that retires, that would be the first scenario, the other scenario is that I may have entered on a date earlier than the selected range in that case I should be counted from the initial date selected.

Ldanielj28_0-1665709440762.png

These are the metrics I have so far to calculate income and withdrawals

Income=

VAR MinDate =
MIN( 'Calendar.HHRR Dates'[Date] )
VAR MaxDate =
MAX( 'Calendar.HHRR Dates'[Date] )
VAR Result =
CALCULATE(
DISTINCTCOUNT( 'HHRR Movements'[AlternateCode] ),
'HHRR Movements'[Active] = TRUE
,'HHRR Movements'[Start_Date_Period] >= MinDate
,'HHRR Movements'[Start_Date_Period] <= MaxDate
)
RETURN
Result

Withdrawals=

VAR MinDate =
MIN( 'Calendar.HHRR Dates'[Date] )
VAR MaxDate =
MAX( 'Calendar.HHRR Dates'[Date] )
VAR Result =
CALCULATE(
DISTINCTCOUNT( 'HHRR Movements'[AlternateCode] ),
'HHRR Movements'[Active] = TRUE
,'HHRR Movements'[End_Date_Period] >= MinDate
,'HHRR Movements'[End_Date_Period] <= MaxDate
)
RETURN
Result

Any help will be very useful. Thanks a lot.

1 REPLY 1
lbendlin
Super User
Super User

You can use your own calendar table or you can use the NETWORKDAYS() function to filter an existing calendar. In any case that calendar table likely needs to be disconnected from the rest of the data model, so that you can do a cross join with all the employees.  Then you can write a measure that calculates if a particular data should be considered a work day for that employee.

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.