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.
Hi
I have an issue that I need to identify all employees who has worked more then three straight working days and then present it in a report. Workingdays is usually mon-fri according to a calender table. A user can work friday, be off on the weekend and then work mon-wed, that would count as four workingdays in a row and thus should show in the report.
My tables look like below and the output should be something like this. Any ideas from the community?
Output:
Name | Nr of days | Interval
Mike | 4 | 2019-08-05 to 2019-08-06
Andrew | 4 | 2019-08-08 to 2019-08-31
Peter is excluded from the list, he has worked four days, but not in straight line (off 2019-08-07)
Calender | ||
Date | Weekday | |
2019-08-05 | 1 | |
2019-08-06 | 1 | |
2019-08-07 | 1 | |
2019-08-08 | 1 | |
2019-08-09 | 1 | |
2019-08-10 | 0 | |
2019-08-11 | 0 | |
2019-08-12 | 1 | |
2019-08-13 | 1 | |
Employee | ||
Name | ||
Mike | ||
Peter | ||
Andrew | ||
Log | ||
Employee | Datefrom | DateTo |
Mike | 2019-08-05 | 2019-08-06 |
Mike | 2019-08-07 | 2019-08-08 |
Peter | 2019-08-05 | 2019-08-06 |
Peter | 2019-08-08 | 2019-08-09 |
Andrew | 2019-08-08 | 2019-08-09 |
Andrew | 2019-08-12 | 2019-08-13 |
Solved! Go to Solution.
Hi @Anonymous ,
At first, you need to create a measure “Nr of days” to get workday numbers.
Nr of days = SUMX ( 'Log', DATEDIFF ( 'Log'[Datefrom], 'Log'[DateTo], DAY ) + 1 )
Then create a measure “Interval” to display the range of date.
Interval = CALCULATE ( MIN ( 'Log'[Datefrom] ) & " TO " & MAX ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) )
Now you can create a measure “Whether the requirements are met” as a logical formula.
Whether the requirements are met = VAR d1 = WEEKDAY ( CALCULATE ( MIN ( 'Log'[Datefrom] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR d2 = WEEKDAY ( CALCULATE ( MIN ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR d3 = WEEKDAY ( CALCULATE ( MAX ( 'Log'[Datefrom] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR d4 = WEEKDAY ( CALCULATE ( MAX ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR count1 = DATEDIFF ( CALCULATE ( MIN ( 'Log'[Datefrom] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), CALCULATE ( MAX ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), DAY ) + 1 RETURN IF ( ( [Nr of days] = 4 && count1 = 4 ) || ( [Nr of days] = 4 && count1 = 6 ) || ( [Nr of days] >= 5 && count1 - [Nr of days] = 2 && ( d2 - d3 ) = 4 ), "True", "FALSE" )
At last, you can use this filed to create a visual.
You can use filter to display what you want.
Best Regards,
Eads
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
At first, you need to create a measure “Nr of days” to get workday numbers.
Nr of days = SUMX ( 'Log', DATEDIFF ( 'Log'[Datefrom], 'Log'[DateTo], DAY ) + 1 )
Then create a measure “Interval” to display the range of date.
Interval = CALCULATE ( MIN ( 'Log'[Datefrom] ) & " TO " & MAX ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) )
Now you can create a measure “Whether the requirements are met” as a logical formula.
Whether the requirements are met = VAR d1 = WEEKDAY ( CALCULATE ( MIN ( 'Log'[Datefrom] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR d2 = WEEKDAY ( CALCULATE ( MIN ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR d3 = WEEKDAY ( CALCULATE ( MAX ( 'Log'[Datefrom] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR d4 = WEEKDAY ( CALCULATE ( MAX ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), 2 ) VAR count1 = DATEDIFF ( CALCULATE ( MIN ( 'Log'[Datefrom] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), CALCULATE ( MAX ( 'Log'[DateTo] ), ALLEXCEPT ( 'Log', 'Log'[Employee] ) ), DAY ) + 1 RETURN IF ( ( [Nr of days] = 4 && count1 = 4 ) || ( [Nr of days] = 4 && count1 = 6 ) || ( [Nr of days] >= 5 && count1 - [Nr of days] = 2 && ( d2 - d3 ) = 4 ), "True", "FALSE" )
At last, you can use this filed to create a visual.
You can use filter to display what you want.
Best Regards,
Eads
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
81 | |
70 | |
62 |
User | Count |
---|---|
148 | |
116 | |
104 | |
90 | |
65 |