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

Error in Comparing Date/Time Columns

 

I am trying to define the shift of a person using his In Time data. But the measure classifies a few time instants incorrectly.

 

The error is only with work shift C.

A, B and Undefined are correct but some instances of them are getting classified as C incorrectly.

 

The measure for WorkShift is:

WorkShift = 
IF(
    (Sheet1[In Time] > TIME(7,0,0) ) && (Sheet1[In Time] < TIME(9,0,0) ) , "A" , 
    IF (   (Sheet1[In Time] < TIME(17,0,0) ) && (Sheet1[In Time] > TIME(15,0,0) ) , "B" , 
        IF(   (Sheet1[In Time] < TIME(1,0,0) ) || (Sheet1[In Time] > TIME(23,0,0)  ) ,"C" ,"UNDEFINED")
    )
)

The pic shows the error (wrong classification):

Error - Wrong classification

https://drive.google.com/file/d/1Tvu3IVCENsI8bm3TrEknerIGIt465oPh/view?usp=sharing

1 ACCEPTED SOLUTION
tex628
Community Champion
Community Champion

Yes, your 'InTime' column is currently time format -> 10:01:01

When you use the TIME() function you will return datetime format -> 1899-01-01 10:01:01

If you create a new column, converting the values that you have in your 'InTime' column using TIME() you should get the same timestamps but in datetime and with 1899-01-01 as the Y/M/D

Use that column instead of the 'InTime' column and the original expression should work.


Connect on LinkedIn

View solution in original post

9 REPLIES 9
tex628
Community Champion
Community Champion

The image link is broken!


Connect on LinkedIn
Anonymous
Not applicable

Yeah, it is not working for some reason. Can you try the google drive link for the same image?

tex628
Community Champion
Community Champion

Honestly, if you just use TIME() on your intime column i think it should work 🙂


Connect on LinkedIn
Anonymous
Not applicable

I could not understand it.

Time(,,) is supposed to convert the parameters to a time format. But the In Time column is already in a time format. I need to compare it to my custom Times.


@tex628 wrote:

Honestly, if you just use TIME() on your intime column i think it should work 🙂


 

tex628
Community Champion
Community Champion

I know it looks weird but TIME() converts to datetime -> 1899-01-01 12:01:01

Try and use it as a measure in a card and watch what it produces!


Connect on LinkedIn
Anonymous
Not applicable

Oh! So is there a work around for my requirement?


@tex628 wrote:

I know it looks weird but TIME() converts to datetime -> 1899-01-01 12:01:01

Try and use it as a measure in a card and watch what it produces!


 

tex628
Community Champion
Community Champion

Yes, your 'InTime' column is currently time format -> 10:01:01

When you use the TIME() function you will return datetime format -> 1899-01-01 10:01:01

If you create a new column, converting the values that you have in your 'InTime' column using TIME() you should get the same timestamps but in datetime and with 1899-01-01 as the Y/M/D

Use that column instead of the 'InTime' column and the original expression should work.


Connect on LinkedIn
Anonymous
Not applicable

Works! Thank you so much

tex628
Community Champion
Community Champion

TIME() Dax syntax converts to datetime:
image.png
So your intime column which only consists of a few hours will always be <1 when compared in the measure!


Connect on LinkedIn

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.