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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
az12
New Member

Time Comparison gives wrong answer

Hi,

 

I'm trying to filter my data (telephone calls events) to only include calls that take place during work hours. Unfortunately the conditional statement I'm using returns the wrong answer from the comparison. Please could anyone help me work out what I'm doing wrong.

 

The formula to see if the call took place before closing time:

az12_1-1677799483171.png

 

The result of the conditional statement (you can clearly see the calls took place before closing time, so the output should be 1 not 0).

az12_0-1677799459946.png

 

Thank you

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@az12 Can't replicate this. Try this though:

Call During Working Hours = IF( ('EVENT'[Local Start Time] - TRUNC('EVENT'[Local Start Time]) ) <= ('EVENT'[Working Day Closing Time] - TRUNC('EVENT'[Working Day Closing Time]) ),1,0)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
az12
New Member

Thank you @Greg_Deckler - the TRUNC fix worked! I'm not entirely sure why I had to do it that way but applying it did the trick :-).

@az12 Great to hear. More than likely, one or both of those columns is actually a date and time column and they are just using a display format of time. That's the most likely cause. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Ashish_Mathur
Super User
Super User

Hi,

Cannot spot a mistake in the formula.  Ensure that the formula is a calculated column formula (not a measure).  If it still does not help, then share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

1. Get rid of the EVENT text in your formula. 

2. Make sure both your time columns are set to the same time format

This worked well for me: 

Len_Barr_0-1677801040459.png

 

 

bharath_v
Resolver I
Resolver I

hi @az12 

It works for me with same formula:

Work Hours? = IF(Appointments[Call Time] <= Appointments[Closing time], 1,0)

 

Hope the time columns have data type as "Time".

bharath_v_0-1677800405584.png

 

@az12 @bharath_v My thought here with the formula I provided is that perhaps one or both of the columns is actually a date/time value but being shown as just a time value format. Using TRUNC the way I demonstrated will get rid of the integer portion (# of days since December 30th, 1899) and then you will only be comparing the decimal portions (fraction of a day).



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@az12 Can't replicate this. Try this though:

Call During Working Hours = IF( ('EVENT'[Local Start Time] - TRUNC('EVENT'[Local Start Time]) ) <= ('EVENT'[Working Day Closing Time] - TRUNC('EVENT'[Working Day Closing Time]) ),1,0)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.