Skip to main content
cancel
Showing results for 
Search instead 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.

Reply
nckpedersen
Helper I
Helper I

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 a crucial piece in calculating the 'jump' to the next stage. For example, here's one opportunity: 

nckpedersen_0-1666042581098.png

I've created a calculated column for each stage with formula:

Time Lead = calculate(MAX('Opportunity History'[CreatedDate]),filter('Opportunity History','Opportunity History'[OpportunityId]='Lead Opps'[ID] && 'Opportunity History'[StageName]="Lead Opportunity"))-calculate(MIN('Opportunity History'[CreatedDate]),filter('Opportunity History','Opportunity History'[OpportunityId]='Lead Opps'[ID] && 'Opportunity History'[StageName]="Lead Opportunity"))
 
That gives me: 

nckpedersen_1-1666042658287.png

 

Is it possible to get the value right after Max? That would close the gaps. 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

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

danextian_0-1666053058884.png

 

Please see attached pbix for reference










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
danextian
Super User
Super User

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

danextian_0-1666053058884.png

 

Please see attached pbix for reference










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

You're incredible, thank you! I've always been tripped up by the 'Earlier' function - really interesting to see it come in here and do the heavy lifting. I was trying to replicate with an "All Except" approach but couldn't use an expression. 

This is amazing work, thank you again. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

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

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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