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
nathan115
Frequent Visitor

Timesheet Hours Calculation

Hi community,

I am new to Power BI, and I have a question about calculating timesheet hours. I have a timesheet table (sample) as follow:

ProjectResourceResource TypeTimesheet StartTimesheet EndTimesheet MonthHoursTimesheet StatusTimesheet CreationForecast Hours
AJohnEmployee9/23/20189/29/201898Frozen9/25/201820.00
AJohnEmployee9/23/20189/29/2018916Frozen9/24/201820.00
BJohnEmployee9/16/20189/22/2018910Pending9/17/201830.00
BJohnEmployee9/16/20189/22/2018910Frozen9/18/201830.00


There are two types of status: frozen and pending. I need to create 2 calculations in the table: Submitted Hours (only include pending hours in a week) and Frozen Hours (aggregate hours for all the previous weeks within curren timesheet month, and less than timesheet creation date). The expected result will be as follow: 

ProjectResourceResource TypeTimesheet StartTimesheet EndTimesheet MonthHoursTimesheet StatusTimesheet CreationForecast HoursFrozen HoursSubmitted Hours
AJohnEmployee9/23/20189/29/201898Frozen9/25/201820.00340
AJohnEmployee9/23/20189/29/2018916Frozen9/24/201820.00260
BJohnEmployee9/16/20189/22/2018910Pending9/17/201830.001010
BJohnEmployee9/16/20189/22/2018910Frozen9/18/201830.00100

Also, for the card visuals, I want to have 2 values: total of forecast hours per project per resource per timesheet month, and total of frozen hours per resource per month, so in this case, Forecast Hours (card visual) will be 50, and Frozen Hours will be 34. This part is optional, so in the meantime I am looking for Frozen hours and Submitted Hours calculation only.

I would really appreciate for your answers!

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @nathan115,

 

Please create two calculated columns like below.

Submitted Hours =
IF (
    TimeSheet[Timesheet Status] = "Pending",
    CALCULATE (
        SUM ( TimeSheet[Hours] ),
        FILTER (
            ALLEXCEPT (
                TimeSheet,
                TimeSheet[Timesheet Month],
                TimeSheet[Timesheet Start],
                TimeSheet[Timesheet End]
            ),
            TimeSheet[Timesheet Status] = "Pending"
        )
    ),
    0
)

Frozen Hours =
CALCULATE (
    SUM ( TimeSheet[Hours] ),
    FILTER (
        ALLEXCEPT ( TimeSheet, TimeSheet[Timesheet Month] ),
        TimeSheet[Timesheet Creation] <= EARLIER ( TimeSheet[Timesheet Creation] )
            && TimeSheet[Timesheet Status] = "Frozen"
    )
)
    + 0

1.PNG

 

For the two values displayed in card visual, please refer to these measures:

total of forecast hours =
VAR temptable =
    SUMMARIZE (
        TimeSheet,
        TimeSheet[Project],
        TimeSheet[Resource],
        TimeSheet[Timesheet Month],
        TimeSheet[Timesheet Start],
        TimeSheet[Timesheet End],
        "Total Forecast", FIRSTNONBLANK ( TimeSheet[Forecast Hours], 1 )
    )
RETURN
    SUMX ( temptable, [Total Forecast] )


total of frozen hours =
CALCULATE (
    MAX ( TimeSheet[Frozen Hours] ),
    ALLEXCEPT (
        TimeSheet,
        TimeSheet[Project],
        TimeSheet[Resource],
        TimeSheet[Timesheet Month]
    )
)

Best regards,

Yuliana Gu

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

View solution in original post

3 REPLIES 3
nathan115
Frequent Visitor

@v-yulgu-msft,

I am trying to create the frozen hour as a measure to make it more dynamic, but I got an error saying "EARLIER refers to an earlier row context which doesn't exit". Do you know how I can modify it to make the frozen hour a measure instead?

v-yulgu-msft
Employee
Employee

Hi @nathan115,

 

Please create two calculated columns like below.

Submitted Hours =
IF (
    TimeSheet[Timesheet Status] = "Pending",
    CALCULATE (
        SUM ( TimeSheet[Hours] ),
        FILTER (
            ALLEXCEPT (
                TimeSheet,
                TimeSheet[Timesheet Month],
                TimeSheet[Timesheet Start],
                TimeSheet[Timesheet End]
            ),
            TimeSheet[Timesheet Status] = "Pending"
        )
    ),
    0
)

Frozen Hours =
CALCULATE (
    SUM ( TimeSheet[Hours] ),
    FILTER (
        ALLEXCEPT ( TimeSheet, TimeSheet[Timesheet Month] ),
        TimeSheet[Timesheet Creation] <= EARLIER ( TimeSheet[Timesheet Creation] )
            && TimeSheet[Timesheet Status] = "Frozen"
    )
)
    + 0

1.PNG

 

For the two values displayed in card visual, please refer to these measures:

total of forecast hours =
VAR temptable =
    SUMMARIZE (
        TimeSheet,
        TimeSheet[Project],
        TimeSheet[Resource],
        TimeSheet[Timesheet Month],
        TimeSheet[Timesheet Start],
        TimeSheet[Timesheet End],
        "Total Forecast", FIRSTNONBLANK ( TimeSheet[Forecast Hours], 1 )
    )
RETURN
    SUMX ( temptable, [Total Forecast] )


total of frozen hours =
CALCULATE (
    MAX ( TimeSheet[Frozen Hours] ),
    ALLEXCEPT (
        TimeSheet,
        TimeSheet[Project],
        TimeSheet[Resource],
        TimeSheet[Timesheet Month]
    )
)

Best regards,

Yuliana Gu

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

Thank you Yuliana! I have to modify couple things here and there, but other than that, the formula works like a charm!

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.