Forum Discussion
Working Days for employees within the selected range
I want to calculate the no. of working days within a selected range through slicer but there are three cases that needs to be kept in mind while calculating the working days:
Lets say start date is 01/01/2019 and finish date is 31/01/2019.
- For normal case the start date and finish date is same (Days:31)
- For new joinee case whose joining date is 10/01/2019 so start date will become 10/01/2019 and finish date is same (Days:21)
- For resigned employee case whose last working day is 15/01/2019 so start date is same and finish date will become 15/01/2019 (Days:16)
- If all are selected (Days: 31+21+16 = 68)
4 Replies
- Greg_Deckler
Community Champion
Sample data would help tremendously. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
But, my Net Work Days Quick Measure might be a starting point. https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362?search-action-id=93924300165&search-result-uid=367362
- AnonymousNot applicable
As per your solution you are using MAX but because of this if more than 1 items are selected then it takes the max value from the column. I want if employee A has 15 days and employee B has 25 days then if both are selected then result should be 40 days but using the MAX the result is coming to be as 50 days.
- v-xicai
Community Support
Hi Anonymous ,
You can create measure like DAX below.
CountDay= VAR MaxDate=CALCULATE(MAX( Table1[Date]), ALLSELECTED( Table1[Date])) VAR EmployeeDate=CALCULATE (FIRSTNONBLANK ( Table1[Date], 1 ),FILTER ( ALLSELECTED( Table1), Table1[Employee Type] = MAX(Table1[Employee Type]) )) VAR _table= SUMMARIZE(Table1,Table1[Employee Type] , "DateDiff", DATEDIFF(EmployeeDate, MaxDate, DAY) ) RETURN SUMX ( _table, [_Value] )If I misunderstood it, could you please share your sample data and desired output screenshots for further analysis? You can also upload sample pbix to OneDrive and post the link here. Do mask sensitive data before uploading.
Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
v-xicai I have two tables one is calender table and another one is the table1 having the data for the joining dates and last working date. So i have crated a all the measures in the calender table and created max date and min date and then doing datediff but when all is selected the answer is coming wrong. The measures are as follows, I am checking that if the entry is in the LastWorkingDay or DateofJoining then take that date otherwise take calendar date against the employee name. I am getting the correct values if indivdual employee is selected but if multiple or all is selected result comes wrong. Greg_Deckler
MinDate =IF(AND(MIN(Table1[DateofJoining]) >= MIN('Calendar'[Date]), MIN(Table1[DateofJoining]) <= MAX('Calendar'[Date])), MIN(Table1[DateofJoining]) , MIN('Calendar'[Date]))MaxDate =IF(AND(MIN('Calendar'[Date]) <= MAX(Table1[LastWorkingDay]), MAX('Calendar'[Date]) >= MAX(Table1[LastWorkingDay])), MAX(Table[LastWorkingDay]), MAX('Calendar'[Date]))Days =DATEDIFF ( [MinDate],[MaxDate], DAY )+1