Forum Discussion
Calculate dates difference between different rows AND columns
- 8 years ago
Hey,
here you will find a little tutorial on how to create Calculated Columns in Power BI
https://docs.microsoft.com/en-us/power-bi/desktop-tutorial-create-calculated-columns
This describes how to use variable in DAX
https://powerbi.tips/2017/05/using-variables-within-dax/This describes the DAX function DATEDIFF
https://msdn.microsoft.com/en-us/query-bi/dax/datediff-function-dax
Regards,
Tom
Hey,
I created two calculated columns, the 1st returns the "Date_Completed" value from the previous Task_ID (currentID - 1) and the 2nd calculates the difference in seconds.
Date_Created_prev =
var currentTaskID = 'Table1'[Task_ID]
return
CALCULATE(
MAX('Table1'[Date_Completed])
,FILTER(
ALL(Table1)
,'Table1'[Task_ID] = currentTaskID - 1
)
)
DateDiff =
DATEDIFF('Table1'[Date_Created],'Table1'[Date_Created_prev],SECOND) Based on your sample data (I tweeked it a little, because I thought there were typos) the result looks like this:
Hopefully this is what you are looking for.
Regards,
Tom
- Anonymous8 years agoNot applicable
Hello,
Wow, that was fast. Sorry for a dummy question, but where to I place this in? Is is a query or what?
What does this mean?
var currentTaskID
And this SECOND?
DateDiff = DATEDIFF('Table1'[Date_Created],'Table1'[Date_Created_prev],SECOND)Thanks!
- TomMartens8 years agoSuper User
Hey,
here you will find a little tutorial on how to create Calculated Columns in Power BI
https://docs.microsoft.com/en-us/power-bi/desktop-tutorial-create-calculated-columns
This describes how to use variable in DAX
https://powerbi.tips/2017/05/using-variables-within-dax/This describes the DAX function DATEDIFF
https://msdn.microsoft.com/en-us/query-bi/dax/datediff-function-dax
Regards,
Tom
- Anonymous8 years agoNot applicable
Thank you, I will investigate that!