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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
android1
Post Patron
Post Patron

Comparing Date/Time Columns

Hi,

 

I have 4 Date/Time columns->[ShiftInTime] [ShiftOutTime] [TimeFrom] [TimeTo]

I am trying to count the total number of times [ShiftInTime] & [ShiftOutTime] is equal to [TimeFrom] & [TimeTo] (and the number of times it's not)

 

I am using this calculated column -> Clocked in by office = IF(Query1[ShiftInTime] && Query1[ShiftOutTime] = Query1[TimeFrom]&&Query1[TimeTo],TRUE(),FALSE())

 

I am not getting any syntax errors but I know the numbers returned are not right.

2 ACCEPTED SOLUTIONS
sdjensen
Solution Sage
Solution Sage

Try this formula instead:

 

IF( Query1[ShiftInTime] = Query1[TimeFrom] && Query1[ShiftOutTime] = Query1[TimeTo], TRUE(), FALSE())
/sdjensen

View solution in original post

Anonymous
Not applicable

@android1 You also probably don't even need this calculated column. You should be able to use a measure instead.

 

Count Clocked In By Office = CALCULATE(

COUNT(Query1[WhateverColumnYouWantToCount]),

FILTER(Query1,

Query1[ShiftInTime] = Query1[TimeFrom] && Query1[ShiftOutTime] = Query1[TimeTo]))

View solution in original post

5 REPLIES 5
sdjensen
Solution Sage
Solution Sage

Try this formula instead:

 

IF( Query1[ShiftInTime] = Query1[TimeFrom] && Query1[ShiftOutTime] = Query1[TimeTo], TRUE(), FALSE())
/sdjensen
Anonymous
Not applicable

@android1 You also probably don't even need this calculated column. You should be able to use a measure instead.

 

Count Clocked In By Office = CALCULATE(

COUNT(Query1[WhateverColumnYouWantToCount]),

FILTER(Query1,

Query1[ShiftInTime] = Query1[TimeFrom] && Query1[ShiftOutTime] = Query1[TimeTo]))

Both solutions work perfectly. Best not to use a calculated column if at all possible.

Thanks a million.

Anonymous
Not applicable

@android1 I think I know what you're trying to write with that formula, but let me translate what you actually wrote back to plain English and maybe the results will make sense:

 

Clocked in by office = If all of the following conditions are met, return true, otherwise return false:

Condition 1. [ShiftInTime] must equal true

Condition 2. [ShiftOutTime] must be the same as [TimeFrom]

Condition 3. [TimeTo] must equal true

 

Every && starts a new, independent condition that must be fully spelled out. The conditions aren't read as part of the same statement like you want them to be. Referencing a column alone in an IF statment just means that column must equal true.

 

I'm a little unclear on how you want the conditions to read. Are you saying you want to know when

A) all four of those columns are the same value, or

B) ShiftInTime = TimeFrom and ShiftOutTime = TimeTo, but ShiftInTime and ShiftOutTime aren't necessarily equal?

Hi,

 

Thanks for the reply. I'm looking to count the number of times both [ShiftInTime] & [ShiftOutTime] is equal

to [TimeFrom] & [TimeTo].

 

If  [ShiftInTime] & [ShiftOutTime] is 01/07/2016 14:00 & 01/07/2016 15:00 and [TimeFrom] & [TimeTo] is 01/07/2016 14:00 & 01/07/2016 15:00 then count should increase by 1.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.