Forum Discussion
Calculating days between Finish Time to Finish Time
Hi Anonymous ,
I observed that the [FINISH DATE] in your sample data is "sorted naturally" ascendingly. Please try using this DAX, it involves using the window function that PowerBI has introduced recently, which also takes me some time to practice:
Days Between =
VAR Data =
PATHITEM(CONCATENATEX(OFFSET(1,ORDERBY('Table (2)'[FINISH DATE],ASC)),[FINISH DATE],"|"),1)
VAR Is_Blank = Data=BLANK()
RETURN IF(Is_Blank,"NULL",ABS(VALUE(VALUE(Data)-MAX('Table (2)'[FINISH DATE]))))
VERY IMPORTANTLY, please ensure your table vis has sorted [FINISH DATE] correctly (ascendingly as per [FINISH DATE]) as shown, unless you don't mind at all about the display order.
For an alternative DAX, inspired by your reply, you can use DATEDIFF() instead of my verison, which is:
Days Between =
VAR Data =
PATHITEM(CONCATENATEX(OFFSET(1,ORDERBY('Table (2)'[FINISH DATE],ASC)),[FINISH DATE],"|"),1)
VAR Is_Blank = Data=BLANK()
RETURN IF(Is_Blank,"NULL", ABS(DATEDIFF(VALUE(Data),MAX('Table (2)'[FINISH DATE]),DAY)))
If your actual data's [FINSIH DATE] is not "sorted naturally", I think you should include a [ROW NUMBER] column in your dataset, created either by SQL selection or other means you used, and then use that [ROW NUMBER] column in your DAX, like the following (you also need to include that [ROW NUMBER] column in your table vis, sorted ascendingly. you can adjust the width of that column to 0 for formatting):
Days Between =
VAR Data =
PATHITEM(CONCATENATEX(OFFSET(1,ORDERBY('Table (2)'[ROW NUMBER],ASC)),[FINISH DATE],"|"),1)
VAR Is_Blank = Data=BLANK()
RETURN IF(Is_Blank,"NULL", [use your own preferred version of calculation here, see above])
- johnyip3 years ago
Solution Sage
hi Anonymous , does this answer your question? If so, kindly accept it as a solution so others facing similar issuescan look for this thread.