Forum Discussion
using RELATED to calculate date difference
- Anonymous1 year ago
Hi JoanMok
The RELATED() function is to return a related value from another table.
Also the RELATED function needs a row context; therefore, it can only be used in calculated column expression, where the current row context is unambiguous, or as a nested function in an expression that uses a table scanning function. A table scanning function, such as SUMX, gets the value of the current row value and then scans another table for instances of that value. The Measure is the Filter Context, so you get the error.
Here are some links for your reference:
Context in DAX Formulas - Microsoft Support
Understanding Context Transition - SQLBI
If you want to calculate the datediff between 2 dates which in one table, you can try this:
Here I create a set of sample:
You can add a calculated column:
Column = DATEDIFF('Table'[Date1],'Table'[Date2],DAY)Or a Measure:
Measure = DATEDIFF(MAX('Table'[Date1]),MAX('Table'[Date2]),DAY) //The Max() function is to get the current row's dateBest Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.