Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Row context filter in table having issues

Hi,

Having an issue in solving this simple problem. so I have a table lets say employeehours having following data:

 

 

The requirement is to have hours worked by employees and a calculation which tell whether an employee is in fatigue  or close to or in No fatigue , some thing like this, the below chart sums up by week and week is present in a slicer :

 

 

so if an employee during a week work for less than 50 h, its no fatigue, <=70 close to fatigue and greater than 70 is high fatigue, date column is not present in it , but when I am creating "Is Fatigue" calculation i think it is taking date into consideration , i only need to have that calcultion apply on what the current data is shown in table. Simple switch statement to calculate "is fatigue" column is below:

 

but it is not calculating correctly, the weekly filter is applied here:

 

 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous,

    Please convert your date fields to the real date value first, then you can try to use the following calculated column formula to get tags based on summary work hour per week for each employee:

    Tag =
    VAR workhour =
        CALCULATE (
            SUM ( Employee[Hours worked] ),
            FILTER ( Employee, [Employee] = EARLIER ( Employee[Employee] ) )
                && YEAR ( [Date] ) = YEAR ( EARLIER ( Employee[Date] ) )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( EARLIER ( Employee[Date] ), 2 )
        )
    RETURN
        IF (
            workhour <= 50,
            "No Fatigue",
            IF ( workhour > 50 && workhour <= 60, "Close to fatigue", "High fatigue" )
        )

    Regards,

    Xiaoxin Sheng

4 Replies

  • Hi,

    You already have a Date column.  Ensure that you also have a Calendar Table with a week number column in there.  Share the link from where i can download your PBI file. 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous,

        Please convert your date fields to the real date value first, then you can try to use the following calculated column formula to get tags based on summary work hour per week for each employee:

        Tag =
        VAR workhour =
            CALCULATE (
                SUM ( Employee[Hours worked] ),
                FILTER ( Employee, [Employee] = EARLIER ( Employee[Employee] ) )
                    && YEAR ( [Date] ) = YEAR ( EARLIER ( Employee[Date] ) )
                    && WEEKNUM ( [Date], 2 ) = WEEKNUM ( EARLIER ( Employee[Date] ), 2 )
            )
        RETURN
            IF (
                workhour <= 50,
                "No Fatigue",
                IF ( workhour > 50 && workhour <= 60, "Close to fatigue", "High fatigue" )
            )

        Regards,

        Xiaoxin Sheng