Forum Discussion
Date difference in same column for different stage in text format
- Anonymous3 years ago
Hi Antonio195754 ,
I think there should be multiple projects which should be keynames and there are multiple stages in them.
Please try this code to create a calculated column.
DateDiff = VAR _PreviousDate = CALCULATE ( MAX ( 'B Opportunity with History'[CREATEDATE] ), FILTER ( ALLEXCEPT ( 'B Opportunity with History', 'B Opportunity with History'[Project] ), 'B Opportunity with History'[CREATEDATE] < EARLIER ( 'B Opportunity with History'[CREATEDATE] ) ) ) VAR _DATEDIFF = DATEDIFF ( IF ( _PreviousDate = BLANK (), 'B Opportunity with History'[CREATEDATE], _PreviousDate ), 'B Opportunity with History'[CREATEDATE], DAY ) RETURN _DATEDIFFResult is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Antonio195754 , try with earlier
DateDiff =
var _PrevDate = maxx(filter('B Opportunity with History', 'B Opportunity with History'[STAGE] = earlier('B Opportunity with History'[STAGE]) -1),'B Opportunity with History'[CREATEDATE])
VAR _PrevDateClean = IF(isblank(_PrevDate),'B Opportunity with History'[CREATEDATE],_PrevDate)
RETURN DATEDIFF(_PrevDateClean,'B Opportunity with History'[CREATEDATE],DAY)
Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
- Antonio1957543 years ago
Helper IV
Thank you amitchandak !
I got it to accept that DAX you provided, but it came back with negative numbers, some in 100's where it really should only be about 30 or so days on average from one stage to another. Is it possible rather than using the stage names 1-4, to use the text names of the stages, e.g. "Assigned", "Working", "Rejected", "Won", where it is days difference from assigned to working, from working to rejected, and working to won?
- Antonio1957543 years ago
Helper IV
These are the columns i'm using amitchandak, for the stages. Prefer to use the text format of the stage names but if numeric works better, all good. Ultimately they will go in scorecards where each card would be, "Assigned to Working", "Working to Won", "Working to Rejected". I feel like i would almost have to make a calculated column for each visual...
- Anonymous3 years agoNot applicable
Hi Antonio195754 ,
I think there should be multiple projects which should be keynames and there are multiple stages in them.
Please try this code to create a calculated column.
DateDiff = VAR _PreviousDate = CALCULATE ( MAX ( 'B Opportunity with History'[CREATEDATE] ), FILTER ( ALLEXCEPT ( 'B Opportunity with History', 'B Opportunity with History'[Project] ), 'B Opportunity with History'[CREATEDATE] < EARLIER ( 'B Opportunity with History'[CREATEDATE] ) ) ) VAR _DATEDIFF = DATEDIFF ( IF ( _PreviousDate = BLANK (), 'B Opportunity with History'[CREATEDATE], _PreviousDate ), 'B Opportunity with History'[CREATEDATE], DAY ) RETURN _DATEDIFFResult is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.