Forum Discussion

BillPoster's avatar
BillPoster
Frequent Visitor
1 year ago
Solved

Power Bi Calendar with Shifts assigned

Hi All, I currently have a calendar that i use in my reports but what I want to do is also say what shift would be working on those dates.  We have 4 shifts that works a 4 week shift pattern as such...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi sandeepsai,
    For your question, we have made a variety of attempts, we have found a way is to shift into two categories, two and two combinations of combinations with the partter ID, can ensure that we carry out a dynamic filtering, and finally use if statements to achieve your needs.

    Shift Measure = 
    VAR SelectedPattern = SELECTEDVALUE('Table'[PatternID], 1)  -- Gets the selected PatternID (default to 1 if none is selected)
    VAR CurrentWeek = MAX('calendar'[WeekOfCycle])  -- Gets the current week of cycle
    VAR CurrentDay = FORMAT(MAX('calendar'[Day]), "ddd")  -- Gets the current day in abbreviated format (e.g., "Mon", "Tue")
    VAR CurrentHour = HOUR(MAX('calendar'[Timestamp]))  -- Gets the current hour from the Timestamp
    
    RETURN
        IF(
            CurrentHour >= 6 && CurrentHour < 18,  -- Day shift hours (6:00 to 18:00)
            CALCULATE(
                SELECTEDVALUE('Table'[Shift 1(combine 1 and 3)]),  -- Day Shift for Shift 1
                'Table'[PatternID] = SelectedPattern,
                'Table'[Week] = CurrentWeek,
                LEFT('Table'[Day], 3) = CurrentDay,
                'Table'[Shift 1(combine 1 and 3)]="D"||'Table'[Shift 1(combine 1 and 3)]="X"
            ),
            IF(
                CurrentHour < 6  ,  -- Night shift hours (18:00 to 6:00)
                CALCULATE(
                    SELECTEDVALUE('Table'[Shift 3 (combine 2 and 4)]),  -- Night Shift for Shift 3
                    'Table'[PatternID] = SelectedPattern,
                    'Table'[Week] = CurrentWeek,
                    LEFT('Table'[Day], 3) = CurrentDay,
                    'Table'[Shift 3 (combine 2 and 4)]="D"||'Table'[Shift 3 (combine 2 and 4)]="N"
                ),
                IF(CurrentHour>=18,
                CALCULATE(
                    SELECTEDVALUE('Table'[Shift 3 (combine 2 and 4)]),  -- Night Shift for Shift 3
                    'Table'[PatternID] = SelectedPattern,
                    'Table'[Week] = CurrentWeek,
                    LEFT('Table'[Day], 3) = CurrentDay,
                    'Table'[Shift 3 (combine 2 and 4)]="D"||'Table'[Shift 3 (combine 2 and 4)]="N"
                ),
                BLANK()
            )
        )
        )

    If you have questions you can check my pbix file, if you have further needs, you can change my pbix file on your own to realize your own latest needs, I hope my thinking can solve your problem, if I can help you solve the problem I will feel honored!

    Hope it helps!

    Best regards,
    Community Support Team_ Tom Shen

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.