Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Calculate Age between Duplicates

I have a table with ticket data where each ticket appears twice - one with the oldest date/time an event occurred, and one with the newest date/time an event occurred. They are labelled in a column a...
  • vicky_'s avatar
    3 years ago

    One way of doing it would be to change the data structure in power query using the pivot functions. 

    So you would have something like 
    Ticket | Incoming Time | Outgoing time | (calculated) time difference.

     

    If you need to keep the data the same, then you could create a calculated column like:
    Age = 

    var outgoingTime = CALCULATE(MAX([Timestamp]), FILTER(ALL([TableName]), [TICKET_ID] = EARLIER([TICKET_ID]) && [DIRECTION] = "Outgoing")

    return DATEDIFF(outgoingTime, [TIMESTAMP], DAY)

    (note that this functio returns a whole number representing the whole days between the two dates)