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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Measure to Compare varying Date and Time with a fixed time variable date.

Hi,

 

After a bit of help if possible.

 

I have a field which looks a bit like this in a very simple way.

Category ||  Date + Time . 

Item 1          11/11/2022 18:00:76

Item 2          11/11/2022  21:08:67

 

Comparison Time to compare to.

Item 1           19:00:00

Item 2           21:00:00

 

The logic I am looking is to add the current date to the fixed time and compare the items to see if before or after.

 

So in the example above Item 1 would be Before and Item 2 would be After.

 

The issue is that the data comes from a model so I cannot add any tables or colums to the data so have to do it in a measure instead.

 

TIA

 

Andy

1 ACCEPTED SOLUTION
MahyarTF
Memorable Member
Memorable Member

Hi @Anonymous ,

Please use below code for create measure :

__Condition =
Var __CurrDate = CALCULATE( Max( Sheet29[Date Time] ) )
Var __Currtime = Time( Hour(__CurrDate), MINUTE(__CurrDate), SECOND(__CurrDate))
Return if( time(Hour(__Currtime),
                MINUTE(__Currtime),
                SECOND(__Currtime)) < Time( Hour(CALCULATE( Max( Sheet30[Time]))),
                                            MINUTE(CALCULATE( Max( Sheet30[Time]))),
                                            SECOND(CALCULATE( Max( Sheet30[Time]))))
           , "Before"
           , "Equal or After"
        )
MahyarTF_0-1668163294954.png

Appreciate your Kudos and Please mark it as a solution if it helps you.

Mahyartf

View solution in original post

1 REPLY 1
MahyarTF
Memorable Member
Memorable Member

Hi @Anonymous ,

Please use below code for create measure :

__Condition =
Var __CurrDate = CALCULATE( Max( Sheet29[Date Time] ) )
Var __Currtime = Time( Hour(__CurrDate), MINUTE(__CurrDate), SECOND(__CurrDate))
Return if( time(Hour(__Currtime),
                MINUTE(__Currtime),
                SECOND(__Currtime)) < Time( Hour(CALCULATE( Max( Sheet30[Time]))),
                                            MINUTE(CALCULATE( Max( Sheet30[Time]))),
                                            SECOND(CALCULATE( Max( Sheet30[Time]))))
           , "Before"
           , "Equal or After"
        )
MahyarTF_0-1668163294954.png

Appreciate your Kudos and Please mark it as a solution if it helps you.

Mahyartf

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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