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

Check if a time is after 7:45pm and before 11pm

I am trying to see if we received entries into a system after 7:45pm and before 11pm on each day. I keep receiving errors that my result set is to large or too small. 

 

How can I return true if I receieve an entry in my recordinsertdate column falls between 7:45pm and 11pm?

 

My current formula is:

 

=IF(AND(TIME([RecordInsertDate],[RecordInsertDate],[RecordInsertDate]) > TIME(19,45,0),
TIME([RecordInsertDate],[RecordInsertDate],[RecordInsertDate]) < TIME(23,0,0)),
"TRUE", "FALSE")

My RecodInsertDate has a value format like  20/06/2017 9:46:19 PM

 

 

1 ACCEPTED SOLUTION

You can consider dates as whole numbers and times as fractions.

Let's take June 22, 2017, 18:00 (or 6:00 PM) as an example.

 

The date value is 42,908 and the time value 0.75, so together 42,908.75.

In order to get the time value, you need to subtract the integer value, so:

42,908.75 - 42,908 = 0.75 which is equivalent with TIME(18,0,0).

 

Furthermore, you want TRUE or FALSE as a result (not the text "TRUE" or "FALSE"), so you can just use the AND function with both conditions, which will return TRUE or FALSE. No IF required. 

Specializing in Power Query Formula Language (M)

View solution in original post

3 REPLIES 3
MarcelBeug
Community Champion
Community Champion

Try this:

 

= AND(([RecordInsertDate]-INT([RecordInsertDate])) > TIME(19,45,0),([RecordInsertDate]-INT([RecordInsertDate])) < TIME(23,0,0))

 

Note: if your time is exactly 19:45:00 or 23:00:00, the formula returns false. If this should be true, change the formula to:

 

= AND(([RecordInsertDate]-INT([RecordInsertDate])) >= TIME(19,45,0),([RecordInsertDate]-INT([RecordInsertDate])) <= TIME(23,0,0))

 

 

Specializing in Power Query Formula Language (M)
Anonymous
Not applicable

Thanks, that works but I don't understand why.

You can consider dates as whole numbers and times as fractions.

Let's take June 22, 2017, 18:00 (or 6:00 PM) as an example.

 

The date value is 42,908 and the time value 0.75, so together 42,908.75.

In order to get the time value, you need to subtract the integer value, so:

42,908.75 - 42,908 = 0.75 which is equivalent with TIME(18,0,0).

 

Furthermore, you want TRUE or FALSE as a result (not the text "TRUE" or "FALSE"), so you can just use the AND function with both conditions, which will return TRUE or FALSE. No IF required. 

Specializing in Power Query Formula Language (M)

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.