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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Ivanfa23
Frequent Visitor

How to use the logical operator "Between" in two times (hours)

Hi community,

 

I have one culumn with format time (ej. 20:00:05, 05:52:00, etc.),

 

Captura.JPG

 

I want to use the IF formula for search for all records that are between 23:00 and 05:00. I try with the next formula:

 

Cruce = IF(Iave[Hora de Cruce ]>TIMEVALUE("23:00:00") && Iave[Hora de Cruce ]<TIMEVALUE("05:00:00"),1,0)

 

but doesn´t work. Any suggestion for resolve this?

 

Regards.

1 ACCEPTED SOLUTION

I have the free version as well.

 

My suspicion is something wrong with your time values, maybe those are regarded as minutes, seconds, fractions or something.

If you try and shift your TIMEVALUE("05:00:00") to TIMEVALUE("00:15:00"), what happens?

 

Just a wild shot, actually I don't understand either why it isn't woking for you.

Specializing in Power Query Formula Language (M)

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

@Ivanfa23,

The formula MarcelBeug provides also works well in my environment. What version of Power BI Desktop do you use? Would you mind sharing me your PBIX file?

Regards,

MarcelBeug
Community Champion
Community Champion

It should be OR (||), not AND (&&).

Specializing in Power Query Formula Language (M)

Hi, I already tried with AND (&&) and OR (||), but doesn´t work, when I do with AND (&&) all records are 0, when ! do with OR (||) all records are 1. Any other idea? Regards.

It works fine with me, but notice the trailing space in column name "Hora de Cruce ".

 

How to use the logical operator Between in two times hours.png

Specializing in Power Query Formula Language (M)

I tried it again but it doesn´t work Smiley Sad

 

Captura.JPG

 

I have Power BI Desktop Free, do you think that's the problem?

 

P.D. I remove the blank of "Hora de Cruce".

 

Regards.

I have the free version as well.

 

My suspicion is something wrong with your time values, maybe those are regarded as minutes, seconds, fractions or something.

If you try and shift your TIMEVALUE("05:00:00") to TIMEVALUE("00:15:00"), what happens?

 

Just a wild shot, actually I don't understand either why it isn't woking for you.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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