Forum Discussion

Joynulali's avatar
Joynulali
Frequent Visitor
2 years ago

Calculate remaining capacity

I'm trying to work out remaining capacity of all employees per week

Each employee has a maximum capacity per week of 5

The table name is Utilisation_Month the columns within the table are Name|Week_Comm|Days_Worked_|Role|Employee Start Date|Employee End Date|Index|

 

An employee can have multiple entries within a week, so this script should also take into consideration if an employee this into account and calculate the remaining capacity per week based on the first occurrence of that week and employee, It should also take into consideration whether or not the employee started working in the team already based off the employee start date and employee end date fields. 

 

This is what I have attempted so far but the value it's returning is incorrect 

 

Remaining Capacity per Employee =

Remaining Capacity per Employee = VAR MaxCapacityPerWeek = 5 RETURN SUMX( FILTER( Utilisation_Month, Utilisation_Month[Week_Comm] = MAX(Utilisation_Month[Week_Comm]) // Adjust based on your calendar selection ), IF( COUNTROWS( FILTER( Utilisation_Month, Utilisation_Month[Name] = EARLIER(Utilisation_Month[Name]) && Utilisation_Month[Week_Comm] = EARLIER(Utilisation_Month[Week_Comm]) ) ) > 1, 0, // Multiple tasks in the same week, no increase in capacity IF( Utilisation_Month[Employee Start Date] <= MAX(Utilisation_Month[Week_Comm]) && (ISBLANK(Utilisation_Month[Employee End Date]) || Utilisation_Month[Employee End Date] >= MAX(Utilisation_Month[Week_Comm])), MaxCapacityPerWeek - COUNTROWS( FILTER( Utilisation_Month, Utilisation_Month[Name] = EARLIER(Utilisation_Month[Name]) && Utilisation_Month[Week_Comm] = EARLIER(Utilisation_Month[Week_Comm]) && Utilisation_Month[Role] = EARLIER(Utilisation_Month[Role]) ) ), 0 // Employee not working in the specified week ) ) ) Sent from Outlook for Android

VAR MaxCapacityPerWeek = 5

RETURN

SUMX(

    FILTER(

        Utilisation_Month,

        Utilisation_Month[Week_Comm] = MAX(Utilisation_Month[Week_Comm]) // Adjust based on your calendar selection

    ),

    IF(

        COUNTROWS(

            FILTER(

                Utilisation_Month,

                Utilisation_Month[Name] = EARLIER(Utilisation_Month[Name]) &&

                Utilisation_Month[Week_Comm] = EARLIER(Utilisation_Month[Week_Comm])

            )

        ) > 1,

        0, // Multiple tasks in the same week, no increase in capacity

        IF(

            Utilisation_Month[Employee Start Date] <= MAX(Utilisation_Month[Week_Comm]) &&

            (ISBLANK(Utilisation_Month[Employee End Date]) || Utilisation_Month[Employee End Date] >= MAX(Utilisation_Month[Week_Comm])),

            MaxCapacityPerWeek - COUNTROWS(

                FILTER(

                    Utilisation_Month,

                    Utilisation_Month[Name] = EARLIER(Utilisation_Month[Name]) &&

                    Utilisation_Month[Week_Comm] = EARLIER(Utilisation_Month[Week_Comm]) &&

                    Utilisation_Month[Role] = EARLIER(Utilisation_Month[Role])

                )

            ),

            0 // Employee not working in the specified week

        )

    )

)

 

2 Replies