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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sraj
Responsive Resident
Responsive Resident

Need to show the negative duration

Hi there,
 
 Is there anyway I can show the negative value if the individual is Moved to the queue [MovedToApp] after the Appt date & time [IN]?
Appt date & time [IN] = 6/07/2023 9:45:00 AMMoved to the queue [MovedToApp] = 6/07/2023  1:01:21 PM03:16:21
 
I am calculating as mentioned below :
# of Secs APPTWAITtime = (DATEDIFF('vw_BiReports_VirtualWaitTimes'[MovedToApp],'vw_BiReports_MeetingWaitTimes'[In],SECOND))
 
Chelsie Eiden's Duration AppWaittime =
 
// We start with a duration in number of seconds
VAR Duration = AVERAGE([# of Secs APPTWAITtime])
// There are 3,600 seconds in an hour
VAR Hours = INT ( Duration / 3600)
// There are 60 seconds in a minute
VAR Minutes = INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
// Remaining seconds are the remainder of the seconds divided by 60 after subtracting out the hours
VAR Seconds = ROUND( MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0) // We round up here to get a whole number
RETURN
// We put the hours, minutes and seconds into the proper "place"
Hours * 10000 + Minutes * 100 + Seconds
 
Can someone please advise?
 
 
 
2 REPLIES 2
AmiraBedh
Resident Rockstar
Resident Rockstar

If I understand your question correctly, you're looking to adjust your DAX formula in such a way that if the `[MovedToApp]` timestamp is after the `[IN]` timestamp, the duration will show as a negative value.

Here's how you can make modifications to reflect this:


You're already calculating the difference in seconds using the `DATEDIFF` function. However, to handle the negative scenario, you can use an `IF` statement:

 

# of Secs APPTWAITtime =
IF(
'vw_BiReports_VirtualWaitTimes'[MovedToApp] > 'vw_BiReports_MeetingWaitTimes'[In],
-DATEDIFF('vw_BiReports_MeetingWaitTimes'[In],'vw_BiReports_VirtualWaitTimes'[MovedToApp],SECOND),
DATEDIFF('vw_BiReports_VirtualWaitTimes'[MovedToApp],'vw_BiReports_MeetingWaitTimes'[In],SECOND)
)

 

Here, if the `[MovedToApp]` timestamp is after the `[In]` timestamp, we make the duration negative.


Using the sign of `Duration`, decide the way you calculate hours, minutes, and seconds.

Chelsie Eiden's Duration AppWaittime =
VAR Duration = AVERAGE([# of Secs APPTWAITtime])
VAR AbsDuration = ABS(Duration) // Get the absolute value for calculations
VAR Hours = INT ( AbsDuration / 3600)
VAR Minutes = INT ( MOD( AbsDuration - ( Hours * 3600 ),3600 ) / 60)
VAR Seconds = ROUND( MOD ( MOD( AbsDuration - ( Hours * 3600 ),3600 ), 60 ),0)

// Decide the sign of the resulting time based on Duration's sign
RETURN
IF(Duration >= 0,
Hours * 10000 + Minutes * 100 + Seconds,
-(Hours * 10000 + Minutes * 100 + Seconds) // Negate the final result for negative durations
)



 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
sraj
Responsive Resident
Responsive Resident

Thank you for your response!! Looks like I am getting close, what can I do return this just in mins? I tried this but doesn't look like its working.  May be the format needs to be updated 00:00:00, can you please advise?

 

RETURN
IF(Duration >= 0,
Minutes * 100,
-(Minutes * 100
)

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.