This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
Hi All,
Can you please help me out. I need to calculate a duration with the following IF considered.
if "index" = 1 then date_replied - date created else
if "index > 1 then date_replied - date replied from the row prior (current index - 1)
I would love to do this in both a DAX and also within Power Query using custom column as i will be looking to average this duration out.
Thanks in advance for any assistance provided.
Todd
Solved! Go to Solution.
Hi @ToddMate ,
You could create a column as below:-
Column =
VAR current_index = 'Table (2)'[index]
VAR prev_index = current_index - 1
VAR current_ticket = [ticket_number]
VAR prev_date_rep =
CALCULATE (
MAX ( 'Table (2)'[date replied] ),
FILTER (
'Table (2)',
'Table (2)'[index] = prev_index
&& 'Table (2)'[ticket_number] = current_ticket
)
)
VAR result =
IF (
current_index = 1,
DATEDIFF ( 'Table (2)'[date created], 'Table (2)'[date replied], SECOND ),
DATEDIFF ( prev_date_rep, 'Table (2)'[date replied], SECOND )
)
VAR _Seconds = result
VAR _Minutes =
INT ( _Seconds / 60 )
VAR _RemainingSeconds =
MOD ( _Minutes, 60 )
VAR _Hours =
INT ( _Minutes / 60 )
VAR _RemainingMinutes =
MOD ( _Minutes, 60 )
VAR _Days =
INT ( _Hours / 24 )
VAR _RemainingHours =
MOD ( _Hours, 24 )
RETURN
FORMAT ( _Days, "00" ) & ":"
& FORMAT ( _RemainingHours, "00" ) & ":"
& FORMAT ( _RemainingMinutes, "00" ) & ":"
& FORMAT ( _RemainingSeconds, "00" )
Output:-
Note:- Minutes and seconds values are vary since i have not added seconds data in the dataset.
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
Hi @ToddMate ,
You could create a column as below:-
Column =
VAR current_index = 'Table (2)'[index]
VAR prev_index = current_index - 1
VAR current_ticket = [ticket_number]
VAR prev_date_rep =
CALCULATE (
MAX ( 'Table (2)'[date replied] ),
FILTER (
'Table (2)',
'Table (2)'[index] = prev_index
&& 'Table (2)'[ticket_number] = current_ticket
)
)
VAR result =
IF (
current_index = 1,
DATEDIFF ( 'Table (2)'[date created], 'Table (2)'[date replied], SECOND ),
DATEDIFF ( prev_date_rep, 'Table (2)'[date replied], SECOND )
)
VAR _Seconds = result
VAR _Minutes =
INT ( _Seconds / 60 )
VAR _RemainingSeconds =
MOD ( _Minutes, 60 )
VAR _Hours =
INT ( _Minutes / 60 )
VAR _RemainingMinutes =
MOD ( _Minutes, 60 )
VAR _Days =
INT ( _Hours / 24 )
VAR _RemainingHours =
MOD ( _Hours, 24 )
RETURN
FORMAT ( _Days, "00" ) & ":"
& FORMAT ( _RemainingHours, "00" ) & ":"
& FORMAT ( _RemainingMinutes, "00" ) & ":"
& FORMAT ( _RemainingSeconds, "00" )
Output:-
Note:- Minutes and seconds values are vary since i have not added seconds data in the dataset.
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 34 | |
| 32 | |
| 25 | |
| 21 | |
| 16 |
| User | Count |
|---|---|
| 61 | |
| 49 | |
| 28 | |
| 23 | |
| 23 |