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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
gkakun
Helper III
Helper III

Time Comparison

Hi, I have a table with timestamp and Im trying to build the logic, if the time is between 20:15 and 8:14 it's "night shift", else, it's" day shift". I tool the hour to different column but the logic doesnt work. Test = if(and('Cust Order Cube'[Create Time]>=TIME(20,15,0),'Cust Order Cube'[Create Time]<=TIME(8,14,59)),"Night","Day") any idea?

 

Capture.JPG

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@gkakun , Logic seem right. Try Or and  Try with .time

 

Test = if(OR('Cust Order Cube'[Create Time]>=TIME(20,15,0),'Cust Order Cube'[Create Time]<=TIME(8,14,59)),"Night","Day")

 

Test = if('Cust Order Cube'[Create Time].time>=TIME(20,15,0) || 'Cust Order Cube'[Create Time].time<=TIME(8,14,59),"Night","Day")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi,  @gkakun 

Here I use  field [Create Date]  rather than [Create Time] to create a calculated column as below:

Test =
IF (
    AND (
        FORMAT ( 'Cust Order Cube'[Create Date], "hh-mm-ss" )
            >= FORMAT ( TIME ( 20, 15, 0 ), "hh-mm-ss" ),
        FORMAT ( 'Cust Order Cube'[Create Date], "hh-mm-ss" )
            <= FORMAT ( TIME ( 8, 14, 59 ), "hh-mm-ss" )
    ),
    "Night",
    "Day"
)

 

 Best Regards,
Community Support Team _ Eason

amitchandak
Super User
Super User

@gkakun , Logic seem right. Try Or and  Try with .time

 

Test = if(OR('Cust Order Cube'[Create Time]>=TIME(20,15,0),'Cust Order Cube'[Create Time]<=TIME(8,14,59)),"Night","Day")

 

Test = if('Cust Order Cube'[Create Time].time>=TIME(20,15,0) || 'Cust Order Cube'[Create Time].time<=TIME(8,14,59),"Night","Day")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.