Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi, community
I'm trying to calculate the average sales cycle length.
In my case, I'm trying to make a difference between data from different rows.
For example, the opportunity 0060Y00000J1tMvQAJ was created on 19/03/2018 (Each new opportunities automatically takes the Challenge stage). This opportunity staid 490 days in Challenge then moved to the stage Value on 22/07/2019, and 3 days later moved to Solution. As you can see an opportunity doesn't have the requirement to go through all the stage (Challenge to Solution, Challenge to Closed Won).
Many thanks.
Solved! Go to Solution.
Hi,
I finally find a way to do it I think there is others way to simplify the formula but it's working.
Many thanks for your contribution.
Days Challenge = IF ( 'Opportunity Field History'[OldValue] = "Challenge"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[Field] = "created" ); 'Opportunity Field History'[CreatedDate]; DAY ); IF ( 'Opportunity Field History'[OldValue] = "Closing"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[NewValue] = "Closing" ); 'Opportunity Field History'[CreatedDate]; DAY ); IF ( 'Opportunity Field History'[OldValue] = "Solution"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[NewValue] = "Solution" ); 'Opportunity Field History'[CreatedDate]; DAY ); IF ( 'Opportunity Field History'[OldValue] = "Value"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[NewValue] = "Value" ); 'Opportunity Field History'[CreatedDate]; DAY ); BLANK () ) ) ) )
Hi,
I finally find a way to do it I think there is others way to simplify the formula but it's working.
Many thanks for your contribution.
Days Challenge = IF ( 'Opportunity Field History'[OldValue] = "Challenge"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[Field] = "created" ); 'Opportunity Field History'[CreatedDate]; DAY ); IF ( 'Opportunity Field History'[OldValue] = "Closing"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[NewValue] = "Closing" ); 'Opportunity Field History'[CreatedDate]; DAY ); IF ( 'Opportunity Field History'[OldValue] = "Solution"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[NewValue] = "Solution" ); 'Opportunity Field History'[CreatedDate]; DAY ); IF ( 'Opportunity Field History'[OldValue] = "Value"; DATEDIFF ( CALCULATE ( MIN ( 'Opportunity Field History'[CreatedDate] ); ALLEXCEPT ( 'Opportunity Field History'; 'Opportunity Field History'[OpportunityId] ); 'Opportunity Field History'[NewValue] = "Value" ); 'Opportunity Field History'[CreatedDate]; DAY ); BLANK () ) ) ) )
Hi Darek,
What I'm after is the cycle length per stage, so the average number of days an opportunity is staying in a specific stage.
Many Thanks
try this code for the measure
Measure = VAR __OpportunityStartEnd = GROUPBY ( 'Opportunites', Opportunites[OpportunityId], "Start", MINX ( CURRENTGROUP (), 'Opportunites'[CreatedDate] ), "End", MAXX ( CURRENTGROUP (), 'Opportunites'[CreatedDate] ) ) VAR __OpportunityLength = ADDCOLUMNS ( __OpportunityStartEnd, "Length", [End] - [Start] ) RETURN AVERAGEX ( __OpportunityLength, [Length] )
Hi Stachu,
Many thanks for your help but it's not working. I did it using excel and for each opportunity ID, I have the number of days staid per stage. For that I was using this formula:
=IF(D427="Value";MAXIFS(F:F;C:C;C427;D:D;D427)-MAXIFS(F:F;C:C;C427;E:E;D427);"")
Many thanks
I think the easiest way to do it is to calculate the cycle length in the calculated column, like this:
Cycle Length = VAR __OpportunityId = 'Opportunites'[OpportunityId] VAR __CreatedDate = 'Opportunites'[CreatedDate] VAR __PreviousStageDate = CALCULATE ( MIN ( 'Opportunites'[CreatedDate] ), FILTER ( ALL ( 'Opportunites' ), 'Opportunites'[OpportunityId] = __OpportunityId && 'Opportunites'[CreatedDate] > __CreatedDate ) ) VAR __PreviousStageDateNoBlanks = IF ( ISBLANK ( __PreviousStageDate ), __CreatedDate, __PreviousStageDate ) RETURN __PreviousStageDateNoBlanks - __CreatedDate
and then calculate the average based on that (I filter out 0 length cycles, as the end of the process is a point in time, and therefore doesn't have length):
Cycle Avg Length = VAR __OpportunityCycleLengthNo0s = FILTER ( 'Opportunites', 'Opportunites'[Cycle Length] <> 0 ) VAR __AverageCyclePerOpportunity = GROUPBY ( __OpportunityCycleLengthNo0s, Opportunites[OpportunityId], "Avg", AVERAGEX ( CURRENTGROUP (), 'Opportunites'[Cycle Length] ) ) RETURN AVERAGEX ( __AverageCyclePerOpportunity, [Avg] )
I used the average to average the averages of multiples IDs (this only shows when you have multiple IDs in the filter context, e.g. in the Total line), is this your intended aggregation on this level?
Hi @Stachu - I'm trying to apply this to a similar situation I'm having. I follwed your first step above and it worked, but the return value is a date, not a time difference. I'd like to calc the DATEDIFF between a previous row value that has the same "OpportunityID". In my case, the Category is called ProjectID.
Any suggestions?
My post is here: DATEDIFF from nonconsecutive rows
User | Count |
---|---|
47 | |
26 | |
21 | |
17 | |
15 |
User | Count |
---|---|
53 | |
34 | |
17 | |
17 | |
15 |