Forum Discussion

Joseph_Hchaime's avatar
Joseph_Hchaime
Icon for Helper III rankHelper III
4 years ago
Solved

Productivity Tracking in DAX

Hi,   I have a table of activities with daily dates and how many hours an employee has worked on that specific day.    Assuming we have 8 working hours per day, and an employee only registered 3,...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Joseph_Hchaime ,

    I created a sample pbix file(see attachment) for you, please check whether that is what you want.You can create the measures as below to get it:

    Untracked Hours Per Day = 
    VAR _whours =
        SUM ( 'activities'[Hours Worked] )
    RETURN
        IF ( ISBLANK ( _whours ), BLANK (), 8 - _whours )
    Untracked Hours Per Week = 
    VAR _selweek =
        SELECTEDVALUE ( 'Date'[Week] )
    VAR _whours =
        CALCULATE (
            SUM ( 'activities'[Hours Worked] ),
            FILTER ( 'activities', WEEKNUM ( 'activities'[Date] ) = _selweek )
        )
    RETURN
        IF ( ISBLANK ( _whours ), BLANK (), 40 - _whours )
    Untracked Hours Per Month = 
    VAR _selmonth =
        SELECTEDVALUE ( 'Date'[Month] )
    VAR _workingdays =
        CALCULATE (
            COUNT ( 'Date'[Date] ),
            FILTER ( 'Date', 'Date'[Month] = _selmonth && 'Date'[Isworkingday] = 1 )
        )
    VAR _whours =
        CALCULATE (
            SUM ( 'activities'[Hours Worked] ),
            FILTER ( 'activities', MONTH ( 'activities'[Date] ) = _selmonth )
        )
    RETURN
        IF ( ISBLANK ( _whours ), BLANK (), _workingdays * 8 - _whours )
    Untracked Hours Per Year = 
    VAR _selyear =
        SELECTEDVALUE ( 'Date'[Year] )
    VAR _workingdays =
        CALCULATE (
            COUNT ( 'Date'[Date] ),
            FILTER ( 'Date', 'Date'[Year] = _selyear && 'Date'[Isworkingday] = 1 )
        )
    VAR _whours =
        CALCULATE (
            SUM ( 'activities'[Hours Worked] ),
            FILTER ( 'activities', YEAR ( 'activities'[Date] ) = _selyear )
        )
    RETURN
        IF ( ISBLANK ( _whours ), BLANK (), _workingdays * 8 - _whours )

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards