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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
IvoA93
New Member

Change Date Time to Shift Identifier

I have a report that i have a date time column. I want to add another column to the data that looks at this field and then does the following

  • Has the value as one of two shift times.
  • The shift times start at 7am & 7pm
  • The 7am shift needs to have a value of the Date from the date time and then the word Day so for example 13/11/24 Day
  • The 7pm shift needs to have a value of the Date from the date time and then the word Night so for example 13/11/24 Night
  • The night shift also needs to include anything before 7am the following day.

Hopefully i have made sense here. Please can someone advise on the best way to do this.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @IvoA93 

Based on your information, I create a sample table:

vyohuamsft_0-1731572293703.png

Then create a calculated column, and try the following DAX expression:

ShiftIdentifier = 
VAR ShiftTime = TIME(HOUR([DateTime]), MINUTE([DateTime]), SECOND([DateTime]))
VAR ShiftDate = FORMAT([DateTime], "MM/dd/yyyy")
RETURN 
IF(
    ShiftTime >= TIME(7, 0, 0) && ShiftTime < TIME(19, 0, 0),
    ShiftDate & " Day",
    IF(
        ShiftTime >= TIME(19, 0, 0) || ShiftTime < TIME(7, 0, 0),
        ShiftDate & " Night",
        BLANK()
    )
)

Here is my preview:

vyohuamsft_1-1731572405476.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi, @IvoA93 

Based on your information, I create a sample table:

vyohuamsft_0-1731572293703.png

Then create a calculated column, and try the following DAX expression:

ShiftIdentifier = 
VAR ShiftTime = TIME(HOUR([DateTime]), MINUTE([DateTime]), SECOND([DateTime]))
VAR ShiftDate = FORMAT([DateTime], "MM/dd/yyyy")
RETURN 
IF(
    ShiftTime >= TIME(7, 0, 0) && ShiftTime < TIME(19, 0, 0),
    ShiftDate & " Day",
    IF(
        ShiftTime >= TIME(19, 0, 0) || ShiftTime < TIME(7, 0, 0),
        ShiftDate & " Night",
        BLANK()
    )
)

Here is my preview:

vyohuamsft_1-1731572405476.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

FreemanZ
Super User
Super User

AnalyticPulse
Super User
Super User

Try adding this calculated column in you table:

Shift =
VAR CurrentDateTime = 'Table'[DateTimeColumn]
VAR ShiftDate = DATE(YEAR(CurrentDateTime), MONTH(CurrentDateTime), DAY(CurrentDateTime))
VAR ShiftStartDay = ShiftDate + TIME(7, 0, 0)
VAR ShiftStartNight = ShiftDate + TIME(19, 0, 0)
VAR NextDayShiftStart = ShiftDate + 1 + TIME(7, 0, 0)

RETURN
IF(
CurrentDateTime >= ShiftStartDay && CurrentDateTime < ShiftStartNight,
FORMAT(ShiftDate, "dd/MM/yy") & " Day",
FORMAT(ShiftDate, "dd/MM/yy") & " Night"
)
https://analyticpulse.blogspot.com/
https://analyticpulse.blogspot.com/p/introduction.html
https://www.youtube.com/@AnalyticPulse

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors