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.
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
The Dax code for the formula is:
any help on how to resolve wouldl be grateful
Solved! Go to Solution.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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 🙂
Time Table code is like this:
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
115 | |
100 | |
88 | |
68 | |
61 |
User | Count |
---|---|
152 | |
120 | |
102 | |
87 | |
68 |