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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
lennox25
Post Patron
Post Patron

Help with filtering on hours between 6am and 8am - formula used wont work :(

Column = 
  VAR __DateTime = [DateTimeColumn]
  VAR __Hour = HOUR(__DateTime)
  VAR __Result = IF( __Hour >= 17 || __Hour < 9 || WEEKDAY(__DateTime,2) > 5,1,0)
RETURN
  __Result

Can anyone help/tell me why when I add another column and change thr hours to >= 6 and <8.  It doesnt work. It gives a 1 in every row and no 0?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @lennox25 ,

 

You may need to reconsider the logic of the code. The logic of OR (||) is to output true if one of the conditions holds, for __Hour >= 6 && __Hour < 8, one of the times of day must be satisfied, so the result is always 1.

vcgaomsft_0-1678151665265.png

Based on the field name, please check if this is the result you want.

Out of Hours Emails Recd 06:00 to 08:00am = 
  VAR __DateTime = [Date & Time]
  VAR __Hour = HOUR('Tablemailbox'[Time])
  VAR __Result = IF( __Hour >= 6 && __Hour <8 || WEEKDAY(__DateTime,2) > 5,1,0)
RETURN
  __Result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

4 REPLIES 4
lennox25
Post Patron
Post Patron

Hi @Anonymous , 

 

It still doesnt work. I have created a sample file, please take a look.https://drive.google.com/file/d/13V4d_qh2NdCOWQaAri2myVGPruxO04-A/view?usp=sharing 

Anonymous
Not applicable

Hi @lennox25 ,

 

You may need to reconsider the logic of the code. The logic of OR (||) is to output true if one of the conditions holds, for __Hour >= 6 && __Hour < 8, one of the times of day must be satisfied, so the result is always 1.

vcgaomsft_0-1678151665265.png

Based on the field name, please check if this is the result you want.

Out of Hours Emails Recd 06:00 to 08:00am = 
  VAR __DateTime = [Date & Time]
  VAR __Hour = HOUR('Tablemailbox'[Time])
  VAR __Result = IF( __Hour >= 6 && __Hour <8 || WEEKDAY(__DateTime,2) > 5,1,0)
RETURN
  __Result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Perfect! Thank you @Anonymous 

Anonymous
Not applicable

Hi @lennox25 ,

 

Is [DateTimeColumn] a column or a measure?

If they are all columns, there should be no problem with the code.

vcgaomsft_0-1678090205468.png

vcgaomsft_1-1678090806770.png

Or you can provide some sample data and explain the expected output.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors