Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SohailNadeem
New Member

Combining Days and Hours to make shifts.

Hi I need help with a function to create shifts of specific duration in days and time. I have Day and time data in two columns as shoun in Picture below. It would be great help please.

Dax Requirement.png

 

1 ACCEPTED SOLUTION

Hi @SohailNadeem 

 

Try this:

Shift = 
VAR _D = [Day]
VAR _T = [Time ]
RETURN
    SWITCH (
        TRUE (),
        _D
            IN { "Sunday", "Monday", "Tuesday", "Wednesday" }
                && _T >= TIMEVALUE ( TIME ( 7, 15, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 17, 45, 00 ) ), "Shift A",
        _D
            IN { "Sunday", "Monday", "Tuesday", "Wednesday" }
                && _T > TIMEVALUE ( TIME ( 00, 00, 01 ) )
                && _T <= TIMEVALUE ( TIME ( 14, 45, 00 ) ), "Shift B",
        _D
            IN { "Sunday", "Monday", "Tuesday", "Wednesday" }
                && _T >= TIMEVALUE ( TIME ( 18, 45, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 23, 59, 59 ) ), "Shift B",
        _D
            IN { "Thursday", "Friday", "Saturday" }
                && _T >= TIMEVALUE ( TIME ( 7, 15, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 17, 45, 00 ) ), "Shift C",
        _D
            IN { "Thursday", "Friday", "Saturday" }
                && _T > TIMEVALUE ( TIME ( 00, 00, 01 ) )
                && _T <= TIMEVALUE ( TIME ( 14, 45, 00 ) ), "Shift D",
        _D
            IN { "Thursday", "Friday", "Saturday" }
                && _T >= TIMEVALUE ( TIME ( 18, 45, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 23, 59, 59 ) ), "Shift D"
    )

 

Output:

VahidDM_0-1639952669250.png

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

5 REPLIES 5
VahidDM
Super User
Super User

Hi @SohailNadeem 

 

Can you post sample data as text and expected output?
Not enough information to go on;

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/

Hi Thank you for your time to respond. I have data of day and time in same data table with no other table relation. Day is in text format and time is in time format. I want to combine day and time to make 4 diffetent shifts (shift A, shift B, shift C and Shift D) time and days of shifts are specified in my first message. Thanks for your help. I want to see shift wise performance.

DayTime Shift (Required Out Put)

Wednesday

2:15 AMShift A
Thursday4:12 AM?
Friday3:46 PM?
Saturday7:24 PM?
Sunday2:13 AM?
Monday6:12 PM?

 

Hi @SohailNadeem 

 

Try this:

Shift = 
VAR _D = [Day]
VAR _T = [Time ]
RETURN
    SWITCH (
        TRUE (),
        _D
            IN { "Sunday", "Monday", "Tuesday", "Wednesday" }
                && _T >= TIMEVALUE ( TIME ( 7, 15, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 17, 45, 00 ) ), "Shift A",
        _D
            IN { "Sunday", "Monday", "Tuesday", "Wednesday" }
                && _T > TIMEVALUE ( TIME ( 00, 00, 01 ) )
                && _T <= TIMEVALUE ( TIME ( 14, 45, 00 ) ), "Shift B",
        _D
            IN { "Sunday", "Monday", "Tuesday", "Wednesday" }
                && _T >= TIMEVALUE ( TIME ( 18, 45, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 23, 59, 59 ) ), "Shift B",
        _D
            IN { "Thursday", "Friday", "Saturday" }
                && _T >= TIMEVALUE ( TIME ( 7, 15, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 17, 45, 00 ) ), "Shift C",
        _D
            IN { "Thursday", "Friday", "Saturday" }
                && _T > TIMEVALUE ( TIME ( 00, 00, 01 ) )
                && _T <= TIMEVALUE ( TIME ( 14, 45, 00 ) ), "Shift D",
        _D
            IN { "Thursday", "Friday", "Saturday" }
                && _T >= TIMEVALUE ( TIME ( 18, 45, 00 ) )
                && _T <= TIMEVALUE ( TIME ( 23, 59, 59 ) ), "Shift D"
    )

 

Output:

VahidDM_0-1639952669250.png

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

smpa01
Super User
Super User

@SohailNadeem 

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/How-to-Get-Your-Question-Answered-Quickly/m-p...

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

This is not the solution to my Problem. Can somebody give me the exact DAX to use in the new Shift Column?

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors