Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreShape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.
Hi all,
Trying to work out how I can calculate how many staff are working each hour without having to expand my fact table into, for example, 15 min intervals between each shift. My timesheet data is pretty typical
PERSONNUM | ShiftStartTimeStamp | ShiftEndTimeStamp | PayCode |
123456 | 01/01/2023 07:00:00 | 01/01/2023 15:30:00 | 01 |
987654 | 01/01/2023 07:00:00 | 01/01/2023 15:30:00 | 01 |
654987 | 01/01/2023 12:00:00 | 01/01/2023 20:30:00 | 01 |
What I want to achieve is a visual that looks like this:
I've tried:
Any idea on the error or how else achieve the result?
Thanks
Carl
Solved! Go to Solution.
Hi @CarlBlunck ,
There are two approaches in the attached pbix. The first one is by using PQ to create rows of hours included in the end and start times. The second approach require san extra table (calculated or through PQ) containing the hours in a day.
Proud to be a Super User!
@danextian this is amazing, thank you so much!!! I went with your second approach. Works perfectly.
Hi @CarlBlunck ,
There are two approaches in the attached pbix. The first one is by using PQ to create rows of hours included in the end and start times. The second approach require san extra table (calculated or through PQ) containing the hours in a day.
Proud to be a Super User!
Hi @danextian,
Thank you for this solution. I have questions for each alternative.
1. The shifts passed midnight dont expand as rows with let in formula, how can i fix it?
2. Person per hour calculation gives me the same (aggregated) result for everyday, how can I get a result split into days?
+
3. I need to calculate Sales per head count, but dividing sales into Person per Hour doenst work. What should I do?
Thanks,
Serhan
Hi @danextian ,
I am so glad I found this! I needed to show person per hour and your first approach worked perfectly for me 🙂
I also need to show person by half hour. How can I use the first approach you attached to do this?
Thank you for your help,
Reine
Hi @Reine ,
Try changing the Hours table to this. Notice that I added the 0.5 increment in the GENERATESERIES function and changed the end value to 23.5 to account for the half an hour increment.
Hours =
ADDCOLUMNS (
GENERATESERIES ( 0, 23.5, 0.5 ),
"hour of the day",
VAR __val = [Value]
VAR _time =
IF ( __val > 12, __val - 12, __val )
VAR _ampm =
IF ( __val >= 12, "pm", "am" )
RETURN
IF (
[Value] = 12,
"12:00 pm",
IF (
[Value] = 0,
"12:00 am",
FORMAT ( DIVIDE ( _time, 24 ), "hh:mm" ) & " " & _ampm
)
),
"hour of the day2", FORMAT ( DIVIDE ( [Value], 24 ), "hh:mm" )
)
Proud to be a Super User!
Hi @danextian , Sorry to bother you again. I went ahead and tried to do it with this approach and it does not work. I notice that in your original file, it doesn't seem to be working properly. In your model, there is a person working until 8:30 pm, but that person isn't being counted at that time. I don't know enough about the code you are using to figure out where the issue is 😞 If you have time can you take a look?
Thank you,
Reine
Thank you @danextian - I actually applied the other approach you demonstrated to my data instead of this one that uses this extra Hours table, because I couldn't quite get this approach to work with my data. If you have time and are so inclined, can you tell me how to do this with the other approach?
Oops. I forgot to change the increment for end time. Should have been 0.5/24 instead of 1/24 to account for the half hour interval. Please see the attached pbix for the details.
Proud to be a Super User!
thank you 🙂
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Check out the November 2024 Power BI update to learn about new features.
User | Count |
---|---|
92 | |
89 | |
83 | |
77 | |
49 |
User | Count |
---|---|
146 | |
137 | |
109 | |
68 | |
55 |