Forum Discussion

awff's avatar
awff
Helper III
3 years ago
Solved

Help! Return earliest date with condition in calculated column

Hi fellow PBI'ers   I've spend hours trying to work this out... I've trying to get the earliest instance of a date to calculate cumulative lifetime of a customer.   Basically, I need the earliest...
  • Jihwan_Kim's avatar
    Jihwan_Kim
    3 years ago

    Hi,

    Thank you for your feedback.

    Please check the below picture and the attached pbix file.

     

     

     

     

  • awff's avatar
    3 years ago

    I think i've managed to tweak the first step DAX to get it to work! 

    Basically added an additional condition to get each latest previous end date per row and check to see if the current row start date is less than that.

     

    Jihwan_Kim thank you so much for your help! True lifesaver 🙂

     

    Step one CC = 
    var _starting = MIN('Data V3'[Start_Date__c])
    VAR _currentrowstartdate = 'Data V3'[Start_Date__c]
    VAR _currentrowenddate = 'Data V3'[End_Date__c]
    VAR _previousrowenddate =
        MAXX (
            FILTER ( 
                'Data V3', 'Data V3'[End_Date__c] <= _currentrowstartdate),
            'Data V3'[End_Date__c]
        )
    VAR _latestlastenddate = 
         MAXX (
            FILTER ( 
                'Data V3', 'Data V3'[End_Date__c] <= _currentrowenddate &&
                'Data V3'[Start_Date__c] < _currentrowstartdate),
            'Data V3'[End_Date__c]
        )
    VAR _diff =
        DATEDIFF ( _previousrowenddate, _currentrowstartdate, DAY )
    VAR _condition =
        IF ( 'Data V3'[Start_Date__c] = _starting || _diff > 90 && 'Data V3'[Start_Date__c] >= _latestlastenddate , 1, 0 )
    RETURN
        _condition