cancel
Showing results 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.

Helper II

## DAX: calculate difference between date/times with conditions

Hi,

I have data of telephone calls with details of each call.

Now I need to calculate the duration of each call if the reason is completed.

So for the call with call_id 123 the duration is 4 minutes.

I have no idea where to start ...
I really would like to learn how to do this.

1 ACCEPTED SOLUTION
Super User

@Dicko

Difference =

VAR __ID = Table2[call_id]
VAR __TIME = Table2[timestamp]
RETURN

IF(
Table2[reason] = "completed",
DATEDIFF(
CALCULATE(
min(Table2[timestamp]),
Table2[call_id] = __ID,
Table2[timestamp] < __TIME,
REMOVEFILTERS(Table2)
),
__TIME,
MINUTE
)
)

Did I answer your question? Mark my post as a solution! and hit thumbs up
2 REPLIES 2
Super User

@Dicko

Difference =

VAR __ID = Table2[call_id]
VAR __TIME = Table2[timestamp]
RETURN

IF(
Table2[reason] = "completed",
DATEDIFF(
CALCULATE(
min(Table2[timestamp]),
Table2[call_id] = __ID,
Table2[timestamp] < __TIME,
REMOVEFILTERS(Table2)
),
__TIME,
MINUTE
)
)

Did I answer your question? Mark my post as a solution! and hit thumbs up
Helper II

Thanks! I learned something new 🙂

Announcements

#### 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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors