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

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.

Reply
Anonymous
Not applicable

Create dax column for day shifts

I have a time column and want to create a column for 3 shifts:

 

Morning -> between 07:31:00 AM and 15:30:00 PM

Afternoon -> between 15:31:00 PM and 23:30:00 PM

Night -> between 23:31:00 PM and 07:30:00 AM

 

I made de following DAX code for a shifts column:

 

shifts =
SWITCH(
TRUE(),
TIMEVALUE('Tabel'[Time]) >= TIME(23,30,0),"Night",
TIMEVALUE('Tabel'[Time]) >= TIME(15,30,0), "Afternoon",
TIMEVALUE('Tabel'[Time]) >= TIME(7,30,0), "Morning"
)
 
I got 4 values in de shift column with :
 
Reda89_0-1639578828387.png

 

Can somebody explain why i am getting blank ?

 

Thank you in advance.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

 

shifts =
SWITCH(
TRUE(),
TIMEVALUE('Tabel'[Time]) >= TIME(23,30,0),"Night",
TIMEVALUE('Tabel'[Time]) >= TIME(15,30,0), "Afternoon",
TIMEVALUE('Tabel'[Time]) >= TIME(7,30,0), "Morning"
TIMEVALUE('Tabel'[Time]) < TIME(7,30,0), "Night"
)

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Why don't you check it by yourself? 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@Anonymous , Try like

 

shifts =
SWITCH(
TRUE(),
TIMEVALUE('Tabel'[Time]) >= TIME(23,30,0),"Night",
TIMEVALUE('Tabel'[Time]) >= TIME(15,30,0), "Afternoon",
TIMEVALUE('Tabel'[Time]) >= TIME(7,30,0), "Morning"
TIMEVALUE('Tabel'[Time]) < TIME(7,30,0), "Night"
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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