Forum Discussion

nckpedersen's avatar
nckpedersen
Helper I
3 years ago
Solved

Time in Stage Calculation

I'm trying to determine how long sales opportunities are staying within pre-designated opportunity stages. While Salesforce does give me a change log that allows me to approximate stages, I'm missing...
  • danextian's avatar
    3 years ago

    Hi nckpedersen ,

     

    For this use case, I'd create an index column to sort each stage by opportunityid

    Index by Opportunity = 
    RANKX (
        FILTER ( 'Table', 'Table'[OpportunityID] = EARLIER ( 'Table'[OpportunityID] ) ),
        'Table'[CreatedDate],
        ,
        asc,
        DENSE
    )
    

    And then I'd create column to get the time difference

    Time Difference = 
    VAR _prev =
        CALCULATE (
            MAX ( 'Table'[CreatedDate] ),
            FILTER (
                'Table',
                'Table'[OpportunityID] = EARLIER ( 'Table'[OpportunityID] )
                    && 'Table'[Index by Opportunity]
                        = EARLIER ( 'Table'[Index by Opportunity] ) - 1
            )
        )
    RETURN
        IF ( _prev = BLANK (), BLANK (), 'Table'[CreatedDate] - _prev )
    

    The above formula will return decimal numbers wherein anything less than one is a portion of a day. Create a measure a measure to convert the difference into number of days/hours/minutes

     

    Sample result

     

    Please see attached pbix for reference