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.
Hi,
I am trying to create a column that determines if the event happened on a day or night shift. Here is the column that I am trying to use to determine the shifts.
A week day shift is 8a-5p
A week night shift is 5p-8a
A weekend day shift is 8a-8p
A weekend night shift is 8p-8a
Of note, I found a similar thread where a user was trying to do this with a similar date column. When I used their switch formulaI received an error that the first 6, is unexpected.
A shift = Mon-Friday 06:00:00-14:00:00
B shift = Mon-Friday 14:00:00-22:00:00
C shift = Sun-Fri 22:00:00-06:00:00
D shift = Sat and Sun 06:00:00-18:00:00
Shift = SWITCH ( TRUE (), AND ( HOUR ( Table[EventTime] ) IN { 6, 7, 8, 9, 10, 11, 12, 13 }, WEEKDAY ( Table[EventTime] ) IN { 2, 3, 4, 5, 6 } ), "A", AND ( HOUR ( Table[EventTime] ) IN { 14, 15, 16, 17, 18, 19, 20, 21 }, WEEKDAY ( Table[EventTime] ) IN { 2, 3, 4, 5, 6 } ), "B", AND ( HOUR ( Table[EventTime] ) IN { 22, 23, 24, 1, 2, 3, 4, 5 }, WEEKDAY ( Table[EventTime] ) IN { 1, 2, 3, 4, 5, 6 } ), "C", AND ( HOUR ( Table[EventTime] ) IN { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, WEEKDAY ( Table[EventTime] ) IN { 6, 7 } ), "D" )
Hi @hickkich
Please refer to attached sample file with the proposed solution.
You need to create a shift table as per the screenshot. You need to edit the same to suit your requirement as you can see that some times return blank values which means that apparently I don't fully understand the timings of the different shifts.
With the help of the shifts table, the shift calculated column will become a simple DAX formula.
Shift =
MAXX (
FILTER (
Shifts,
Shifts[Weekday Number] = WEEKDAY ( Data[CreationInstant], 2 )
&& TIMEVALUE ( Data[CreationInstant] ) >= Shifts[StartTime]
&& TIMEVALUE ( Data[CreationInstant] ) <= Shifts[EndTime]
),
Shifts[Shift]
)
hi @hickkich
try like:
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 |
---|---|
45 | |
25 | |
19 | |
16 | |
8 |
User | Count |
---|---|
61 | |
50 | |
45 | |
20 | |
17 |