cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper III
Helper III

How can i get a comparisson from a datetime with a time column?

Screenshot 2020-11-27 085451.png

My initial tought was "Oh, the same way we have:

 

'Table'[Column].[Date]

 

 

to compare only 2 dates from columns, we probably have:

 

'Table'[Column].Time

 

 

"
But we dont, then i thought 
I can use "Hour('Table'[Column])" to compare, but nonono, i cant, cuz will only compare the hour, so if an item have the same hours but minutes different it will not make a good comparisson. 

I cant change my Time column to a datetime.
I know i can create a new column just to get my time from my datetime column, but  i would rather know if there is another way.

1 ACCEPTED SOLUTION
Community Support
Community Support

Hi @Vieiraguilherme ,

You can create a measure as below:

Measure = 
var _datetime=FORMAT(MAX('Table'[Datetime]),"mm/dd/yyyy hh:nn:ss") 
var _time =FORMAT(CONCATENATE(CONCATENATE(FORMAT(MAX('Table'[Datetime]),"mm/dd/yyyy")," "),FORMAT(MAX('Table'[time]),"hh:nn:ss")),"mm/dd/yyyy hh:nn:ss") 
return IF(DATEDIFF(_time,_datetime,HOUR)<=0,"X","Y")

time comparasion.JPG

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

Community Support Team _ Rena
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
Community Support
Community Support

Hi @Vieiraguilherme ,

You can create a measure as below:

Measure = 
var _datetime=FORMAT(MAX('Table'[Datetime]),"mm/dd/yyyy hh:nn:ss") 
var _time =FORMAT(CONCATENATE(CONCATENATE(FORMAT(MAX('Table'[Datetime]),"mm/dd/yyyy")," "),FORMAT(MAX('Table'[time]),"hh:nn:ss")),"mm/dd/yyyy hh:nn:ss") 
return IF(DATEDIFF(_time,_datetime,HOUR)<=0,"X","Y")

time comparasion.JPG

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

Community Support Team _ Rena
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

Super User IV
Super User IV

@Vieiraguilherme , As new column , one of the two

 

if('Table'[Datetime].Time <'Table'[Time] ,"X", "Y")

if(time(Hour('Table'[Datetime]),minute('Table'[Datetime]),second('Table'[Datetime]))<'Table'[Time] ,"X", "Y")



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

@amitchandak , u sure that the "if('Table'[Datetime].Time <'Table'[Time] ,"X", "Y")" works? 
Cuz when i use the ".Time" it doesnt work. 

 

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors