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
paw2
Regular Visitor

last 12 hours flag

Hi,

 

I have a Time Range field like below. Please can you help me to derive Expected Flag like below. From current time to last 12 hours need to flag it as Last 12 hours else  >Last 12 hours.

 

Time Range                                 Expected Flag

Wed, 15 Feb 2023 07:51:22        Last 12 hours

Wed, 15 Feb 2023 06:20:26        Last 12 hours

Tue, 14 Feb 2023 15:23:35          >Last 12 hours

 

I have tried below logic

Flag = if(MAX('Table1'[Time Range])<=NOW() && MAX('Table1'[Time Range])>=NOW()-12/24,"Last 12 hrs"," > Last 12 hrs") but agetting all records as >Last 12 hours only.
1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@paw2  You could try using DATEDIFF:

 

Flag = 
VAR _HoursDiff =  
DATEDIFF( MAX( 'Table1'[Time Range] ) , NOW(), HOUR) 
RETURN
SWITCH( TRUE(),

  _HoursDiff >= 12, "> Last 12 hrs",
 _HoursDiff >= 0, "Last 12 Hours",
"Future Time"
)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

1 REPLY 1
AllisonKennedy
Super User
Super User

@paw2  You could try using DATEDIFF:

 

Flag = 
VAR _HoursDiff =  
DATEDIFF( MAX( 'Table1'[Time Range] ) , NOW(), HOUR) 
RETURN
SWITCH( TRUE(),

  _HoursDiff >= 12, "> Last 12 hrs",
 _HoursDiff >= 0, "Last 12 Hours",
"Future Time"
)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.