Forum Discussion
Date difference in same column with duplicate dates
- Anonymous4 years ago
alam6 , yes that's right, add an Index Column via "Transform Data", then "Add Column", then "Index Column"
Then the DAX for the Calculated Column for [Date Diff] should be as per below. The [Index] field used in the Calculated Column DAX must be the name of the index column you created.
Date Diff = VAR vCompletedDatePriorRow = CALCULATE( MAX('Site Table'[Completed Date]) ,FILTER(ALLEXCEPT('Site Table', 'Site Table'[Site Name]) ,'Site Table'[Index] < EARLIER('Site Table'[Index]) ) ) RETURN DATEDIFF(vCompletedDatePriorRow, 'Site Table'[Completed Date], DAY)This gives me the correct results:
This will also work when there are 3 or 4 etc visits to a site on the same day.
Bear in mind that for this solution to work correctly with an index column, the spreadsheet must be sorted by SiteName and Completed date. If not, it may not work correctly.
alam6 , yes that's right, add an Index Column via "Transform Data", then "Add Column", then "Index Column"
Then the DAX for the Calculated Column for [Date Diff] should be as per below. The [Index] field used in the Calculated Column DAX must be the name of the index column you created.
Date Diff =
VAR vCompletedDatePriorRow =
CALCULATE(
MAX('Site Table'[Completed Date])
,FILTER(ALLEXCEPT('Site Table', 'Site Table'[Site Name])
,'Site Table'[Index] < EARLIER('Site Table'[Index])
)
)
RETURN
DATEDIFF(vCompletedDatePriorRow, 'Site Table'[Completed Date], DAY)
This gives me the correct results:
This will also work when there are 3 or 4 etc visits to a site on the same day.
Bear in mind that for this solution to work correctly with an index column, the spreadsheet must be sorted by SiteName and Completed date. If not, it may not work correctly.
This has worked so far, thank you very much Anonymous!