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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

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 @Anonymous 

 

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 @Anonymous 

 

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/

Anonymous
Not applicable

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 @Anonymous 

 

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

@Anonymous 

 

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

 

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
Anonymous
Not applicable

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors