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
Anonymous
Not applicable

Create report with employees who has worked >3 straight workingdays

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  
DateWeekday 
2019-08-051 
2019-08-061 
2019-08-071 
2019-08-081 
2019-08-091 
2019-08-100 
2019-08-110 
2019-08-121 
2019-08-131 
   
Employee  
Name  
Mike  
Peter  
Andrew  
   
Log  
EmployeeDatefromDateTo
Mike2019-08-052019-08-06
Mike2019-08-072019-08-08
Peter2019-08-052019-08-06
Peter2019-08-082019-08-09
Andrew2019-08-082019-08-09
Andrew2019-08-122019-08-13
1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

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.1-1.PNG

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.

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

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.1-1.PNG

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.

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

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.