Forum Discussion

Antonio195754's avatar
Antonio195754
Helper IV
3 years ago
Solved

Date difference in same column for different stage in text format

Could someone please help with this DAX?    I'm wanting to find the date difference where i have a date column and another column that tells me a stage a given sale is in.  STAGE column includes st...
  • Anonymous's avatar
    Anonymous
    3 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
        _DATEDIFF

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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