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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
rixmcx59
Helper V
Helper V

Calculate Duration between phases from an Audits table

Hello all, trying to find the best approach to get the duration of each Phase in the data below, I have an expression that's getting the duration from the audit dates but I need to use the createdonAccount date to get the first date. I need to calculate all durations, from when the customer was created in the accounts table, to the first change, second change, third change and so-on. then I need the final duration which is the last change until Now()

accounts.namelogicalNamecreatedonAccountcreatedonAuditsOldPhaseNewPhaseDurationIndex
Customer Aaudits_phase2/13/2024 1:213/20/2024 17:27NewCustomerPhase 0 7865
Customer Aaudits_phase2/13/2024 1:213/21/2024 15:12Phase 0Phase 317986
Customer Aaudits_phase2/13/2024 1:214/3/2024 19:54Phase 3Phase 4139961
Customer Baudits_phase2/26/2024 18:242/26/2024 18:250NewCustomer 1518
Customer Baudits_phase2/26/2024 18:243/6/2024 17:53NewCustomerPhase 394611
Customer Baudits_phase2/26/2024 18:243/14/2024 22:21Phase 3NewCustomer86817
Customer Baudits_phase2/26/2024 18:243/18/2024 16:50NewCustomerPhase 347337
Customer Baudits_phase2/26/2024 18:243/27/2024 22:11Phase 3Phase 498964

The expression I am using now

Duration = 
VAR temp =
    TOPN (
        1,
        FILTER (
            audits,
            audits[accounts.name] = EARLIER ( audits[accounts.name]  )
                && audits[createdonAudits] < EARLIER ( audits[createdonAudits] )
        ),
        [createdonAudits], DESC
    )
RETURN
    DATEDIFF ( MINX ( temp, [createdonAudits] ), audits[createdonAudits], DAY )

 

Thanks for any help

 

3 REPLIES 3
rixmcx59
Helper V
Helper V

Yes, for cutomer A, line 1, the first duration would be between the createdonAccount date 2/13/2024 and the earliest createdonAudit date 3/20/2024, so Customer A result shound have a start and end date for each Phase like below

New Customer To Phase 0 = 37 days  3/20/24 - 2/13/24

Phase 0 To Phase 3            = 1 day      3/21/24 - 3/20/24

Phase 3 To Phase 4            = 13 days   4/3/24 - 3/21/24

Phase 4 To Now()               =  Now() - 4/3/24

thanks for the resonse

Anonymous
Not applicable

Hi @rixmcx59 ,

Do you have an idea of what to expect, so that we can solve your problem better?

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello, after looking into the Audits data, there is a created date identified by a change type column, so now the the calculated column is working. I just need to figure out how to get the current duration, which is the days since the last change date and Now(), I'm guessing I need to add a calendar table and use todays date as the end date.

Thanks

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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