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
Anonymous
Not applicable

Shift Report over 24hr clock by Time and Day

Good Morning,

 

I am trying to creatr a report from some shift data.  For example a person Starts there Shift at 08:00 in the morning and finishes at 17:00.  I want to report on the number of people that are working during any 15 minute period, given that employees will start and end at different times.

 

I have been able to to write some DAX code that will allocate the shift pattern across the different 15 miunte periods. However I run in to problems when trying to aggregate the results.

 

The digram belwo shows the 3 rows of data (3 shifts) and the results.  which it shows for example that it is aggregating to 3 for 9.45 instead of 1

 

RodneyArbon_0-1604054461163.png

The Dax code for the formula is:

 

Step Through Time Calculation V3 =
VAR MaxTime = MAXX(TimeTable,[Time]) -- 23:59:59
VAR MinTime = MINX(TimeTable,[Time]) -- 00:00:00
VAR ShiftStartTime = MINX(shifts,[SharedstartTime])
VAR ShiftEndTime = MAXX(Shifts,[SharedEndTime])
VAR ShiftTime = ShiftEndTime - ShiftStartTime -- 07:15:00
VAR TimeFromStartDate = MAXX(Shifts,[SharedStartTime]) - MinTime-- 08:00:00
VAR TimeFromEndate = MAXX(Shifts,[SharedEndTime]) - MaxTime -- + ShiftTime -- 15:15:00
VAR MaxDate = MAXX('Calendar',[Date])
VAR InShift = IF(AND(MaxTime>=ShiftStartTime, MinTime <= ShiftEndTime),[Shiftcount],0)
RETURN
if(HASONEVALUE('Shifts'[Date]),Inshift,sumx(VALUES('Shifts'[Date]),[Shiftcount]) )

 

any help on how to resolve wouldl be grateful

 

 

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Here is how I would approach this in a matrix visual.

 

1.  Make a disconnected table of times in the query editor with = List.Times(#time(0,0,0),96,#duration(0,0,15,0)), convert to table, rename it, and load it.  

 

2. Make a matrix visual with this new column as the columns

 

3.  Use a measure like this to count the number of people working during that timeslot.  TimeSlot is the table with the 15 min increments from step 1)

 

Num of Employees =
VAR mintime =
    MIN ( Timeslots[TimeSlot] )
VAR maxtime =
    MAX ( Timeslots[Timeslot] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table[EmployeeID] ),
        Table[StartTime] <= maxtime,
        Table[StopTime] >= mintime
    )

 

You should be able to use your Date column on rows in the matrix.

 

Regards,

Pat

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

Here is how I would approach this in a matrix visual.

 

1.  Make a disconnected table of times in the query editor with = List.Times(#time(0,0,0),96,#duration(0,0,15,0)), convert to table, rename it, and load it.  

 

2. Make a matrix visual with this new column as the columns

 

3.  Use a measure like this to count the number of people working during that timeslot.  TimeSlot is the table with the 15 min increments from step 1)

 

Num of Employees =
VAR mintime =
    MIN ( Timeslots[TimeSlot] )
VAR maxtime =
    MAX ( Timeslots[Timeslot] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table[EmployeeID] ),
        Table[StartTime] <= maxtime,
        Table[StopTime] >= mintime
    )

 

You should be able to use your Date column on rows in the matrix.

 

Regards,

Pat

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks Thats great.  I think I over thought this solution.

 

Any ideas of how to get this to work when the start time is in one day but the end time is in the next day.

 

for example > StartDate and Time  30/10/2020  22:00     > EndDate and Time 31/10/2020  05:00

 

thsi is neded for peopel who work nights 

 

thanks 🙂

 

 

 

Anonymous
Not applicable

Time Table code is like this:

 

TimeTable =
VAR HourTable = SELECTCOLUMNS(GENERATESERIES(0, 23), "Hour", [Value])
VAR MinuteTable = SELECTCOLUMNS(GENERATESERIES(0, 59), "Minute", [Value])
VAR SecondsTable = SELECTCOLUMNS(GENERATESERIES(0, 59), "Second", [Value])
RETURN
ADDCOLUMNS(
CROSSJOIN(HourTable, MinuteTable,SecondsTable),"Time", TIME([Hour], [Minute], [Second]),
"Time15", If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("00:15:00"),TIMEVALUE("00:15:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("00:30:00"),TIMEVALUE("00:30:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("00:45:00"),TIMEVALUE("00:45:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("01:00:00"),TIMEVALUE("01:00:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("01:15:00"),TIMEVALUE("01:15:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("01:30:00"),TIMEVALUE("01:30:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("01:45:00"),TIMEVALUE("01:45:00"),
If(TIME([Hour], [Minute], [Second])<=TIMEVALUE("02:00:00"),TIMEVALUE("02:00:00"),
 
and data model..
 
 
 

Capture.PNG

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.