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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Spudduk
Frequent Visitor

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 @Spudduk ,

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 @Spudduk ,

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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