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

Cumulative working hours vs daily targets across all dates

Hello,

 

I'm struggling getting the correct totals for a time recording/ tracking report. Also, early apology for the massive post - I just wanted to include as much info as possible.

 

Right, I have a date dimension table and a fact table with the number of hours worked like below:

 

pbiforum01.PNG

 

Each employee has a daily target of 7 hours. Therefore, even though this might be unecessary, i've included a column of ExpectedHours in the DateDimension table.

 

I need to be able to show how much time is missing per day, per employee and be able to roll that up for the week/ month/ year etc. I created a measure to sum the hours but the issue i'm getting is when an employee hasn't recorded any time at all for the day. 

 

I partly got this working with IF(ISNULL for both adding a 0 to the HoursRecorded sum and a 7 to the ExpectedHours sum for where records do not exist. Example below (red line is where the data was missing/ green highlight is where it's fixed):

 

pbiforum02.PNG

 

However, i'm getting an issue with the Totals for all of the sums that have the ISNULL check. It seems that, whilst the nulls are filled with the relavent 0' and 7's, these aren't included in the total calculations. Example for one employee below:

 

pbiforum03.PNG

 

In the example above (left table), you can see that the totals for ExpectedHours and HoursMissing (the sum of ExpectedHours minus the sum of HoursRecorded) aren't including the numbers where 0 time is recorded. I'd like to get the results in the table (above right) and filter out weekends etc. myself.

 

I've seen similar issues with the totals not adding up but none that have the required numbers to be forced where nulls exist.

 

Help will be much appreciated!

 

 

1 ACCEPTED SOLUTION
hemalpatel
Frequent Visitor

I think i've got it! I stayed up till 3am to figure this out and, to my embarrassment, it looks like it should not have taken anywhere near this long to figure out.

 

So, i kept with a column [ExpectedHours] in the dates table as this number is a daily requirement. The formula being:

DailyExpectedHours = SUM(DimDate_Event[ExpectedHours])+IF(ISBLANK(SUM(DimDate_Event[Date])),7.0,0)

 The IF(ISBLANK... sorted out the additional 7 hours per day in my above post.

 

The bit that really worked - I used SUMX, SUMMARIZE, CALCULATE to sum up the hours per day, per user for time entries that have been submitted (posted) like so:

HoursPosted = 
SUMX(
    SUMMARIZE(FctTimeEntry, FctTimeEntry[TimekeeperUserID], DimDate_Event[Date]),
    CALCULATE(IF(SUM(FctTimeEntry[Hours])>[DailyExpectedHours],[DailyExpectedHours], SUM(FctTimeEntry[Hours])), FctTimeEntry[Status] = "Posted")+0
)

 

Then, finally, the subtraction and IF() to avoid negative numbers:

HoursMissing_Posted = 
VAR _MissingHoursTotal = [DailyExpectedHours]-[HoursPosted]
return IF(_MissingHoursTotal < 0, 0, _MissingHoursTotal)

 

This seems to be working right now though feedback on what i've done would be greatfully appreciated as i'm very much still learning Power BI.

 

Thanks to @amitchandak for the "+0" tip - don't think i could have worked this out without that.

View solution in original post

4 REPLIES 4
hemalpatel
Frequent Visitor

I think i've got it! I stayed up till 3am to figure this out and, to my embarrassment, it looks like it should not have taken anywhere near this long to figure out.

 

So, i kept with a column [ExpectedHours] in the dates table as this number is a daily requirement. The formula being:

DailyExpectedHours = SUM(DimDate_Event[ExpectedHours])+IF(ISBLANK(SUM(DimDate_Event[Date])),7.0,0)

 The IF(ISBLANK... sorted out the additional 7 hours per day in my above post.

 

The bit that really worked - I used SUMX, SUMMARIZE, CALCULATE to sum up the hours per day, per user for time entries that have been submitted (posted) like so:

HoursPosted = 
SUMX(
    SUMMARIZE(FctTimeEntry, FctTimeEntry[TimekeeperUserID], DimDate_Event[Date]),
    CALCULATE(IF(SUM(FctTimeEntry[Hours])>[DailyExpectedHours],[DailyExpectedHours], SUM(FctTimeEntry[Hours])), FctTimeEntry[Status] = "Posted")+0
)

 

Then, finally, the subtraction and IF() to avoid negative numbers:

HoursMissing_Posted = 
VAR _MissingHoursTotal = [DailyExpectedHours]-[HoursPosted]
return IF(_MissingHoursTotal < 0, 0, _MissingHoursTotal)

 

This seems to be working right now though feedback on what i've done would be greatfully appreciated as i'm very much still learning Power BI.

 

Thanks to @amitchandak for the "+0" tip - don't think i could have worked this out without that.

Hi @hemalpatel ,

 

Glad to hear that. Please accept your reply as the solution. Your contribution is highly appreciated.

 

 

Best Regards,

Icey

amitchandak
Super User
Super User

@hemalpatel ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

This seems correct. Need to check with data

 

following measures should work

exp = sum(Table[ExpectedHours])+0

rec =Sum(Table[Hoursrecorded])+0

 

missing = [exp]-[rec]

Thanks, @amitchandak . I've just tried your suggestion - below are the results:

pbiforum04.PNG

 

 

The individual records for ExpectedHours now have 14 on dates where time was recorded (though this should remain 7). Also, it seems the totals are adding up 7 hours for each day where time recordings exist i.e. 7*4 = 35.

 

I'm new to posting on this forum and couldn't see where to attach a .csv. Below is some tabular data for the two tables i use. I've only put in about two/three weeks worth of data (for two timekeepers) as it's enough to include full 7 hour days, partial days and zero hour days.

 

[TimeEntry]

TimekeeperIDEventDateHours
74118/10/2020 00:000.5
74119/10/2020 00:000.2
74119/10/2020 00:000.4
74119/10/2020 00:000.8
74119/10/2020 00:001.9
74119/10/2020 00:009.2
36720/10/2020 00:000.2
36720/10/2020 00:000.7
36720/10/2020 00:000.8
36720/10/2020 00:001
36720/10/2020 00:001.3
36720/10/2020 00:001.5
36720/10/2020 00:002
74120/10/2020 00:001.9
74120/10/2020 00:009.6
36721/10/2020 00:000.3
36721/10/2020 00:000.4
36721/10/2020 00:001.3
36721/10/2020 00:001.5
36721/10/2020 00:002
74121/10/2020 00:000.6
74121/10/2020 00:008.4
36722/10/2020 00:000.2
36722/10/2020 00:000.4
36722/10/2020 00:000.5
36722/10/2020 00:001.5
36722/10/2020 00:004.6
74122/10/2020 00:000.5
74122/10/2020 00:002.8
36723/10/2020 00:000.3
36723/10/2020 00:000.8
36723/10/2020 00:000.9
36723/10/2020 00:002
74123/10/2020 00:001.4
36726/10/2020 00:000.3
36726/10/2020 00:000.8
36726/10/2020 00:000.9
74126/10/2020 00:004.9
36727/10/2020 00:000.2
36727/10/2020 00:000.3
36727/10/2020 00:000.6
36727/10/2020 00:000.7
36727/10/2020 00:001.6
74127/10/2020 00:004.9
36728/10/2020 00:000.4
36728/10/2020 00:000.5
74128/10/2020 00:008.3
36729/10/2020 00:000.8
36729/10/2020 00:001.4
74129/10/2020 00:007.8
36730/10/2020 00:000.2
36730/10/2020 00:000.4
74130/10/2020 00:003.7
36702/11/2020 00:000.3
36702/11/2020 00:000.4
36702/11/2020 00:000.7
36703/11/2020 00:000.3
36703/11/2020 00:000.4
36703/11/2020 00:001.2
36705/11/2020 00:000.3
36705/11/2020 00:000.4
36705/11/2020 00:001.7
36706/11/2020 00:000.2
36706/11/2020 00:000.3
36706/11/2020 00:000.5
36706/11/2020 00:000.7
36706/11/2020 00:000.8

 

[DimDate]

DateIsWeekend
05/10/2020 00:00FALSE
06/10/2020 00:00FALSE
07/10/2020 00:00FALSE
08/10/2020 00:00FALSE
09/10/2020 00:00FALSE
10/10/2020 00:00TRUE
11/10/2020 00:00TRUE
12/10/2020 00:00FALSE
13/10/2020 00:00FALSE
14/10/2020 00:00FALSE
15/10/2020 00:00FALSE
16/10/2020 00:00FALSE
17/10/2020 00:00TRUE
18/10/2020 00:00TRUE
19/10/2020 00:00FALSE
20/10/2020 00:00FALSE
21/10/2020 00:00FALSE
22/10/2020 00:00FALSE
23/10/2020 00:00FALSE
24/10/2020 00:00TRUE
25/10/2020 00:00TRUE
26/10/2020 00:00FALSE
27/10/2020 00:00FALSE
28/10/2020 00:00FALSE
29/10/2020 00:00FALSE
30/10/2020 00:00FALSE
31/10/2020 00:00TRUE
01/11/2020 00:00TRUE
02/11/2020 00:00FALSE
03/11/2020 00:00FALSE
04/11/2020 00:00FALSE
05/11/2020 00:00FALSE
06/11/2020 00:00FALSE

 

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.