Forum Discussion
Calculated Column's formula is based on a value in a column
- Anonymous6 years ago
Hi Anonymous
You can't use the formula in columns, but you can use switch function like lbendlin 's reply to calculate date difference.
In addition to lbendlin 's reply, I build a table to have a test.
Build a calculated column:
Date Difference = VAR _DateDifferenceCalucation = CALCULATE(MAX('Calculation'[Date Difference Calculation]),FILTER('Calculation','Calculation'[Country]=EARLIER('Table'[Country]))) VAR _Closed_Created = DATEDIFF ( 'Table'[Created Date], 'Table'[Closed Date], DAY ) VAR _Closed_Assigned = DATEDIFF ( 'Table'[Assigned Date], 'Table'[Closed Date], DAY ) VAR _Closed_Completed = DATEDIFF ( 'Table'[Completed Date], 'Table'[Closed Date], DAY ) VAR _Completed_Assigned = DATEDIFF ( 'Table'[Assigned Date], 'Table'[Completed Date], DAY ) VAR __Completed_Created = DATEDIFF ( 'Table'[Created Date], 'Table'[Completed Date], DAY ) RETURN SWITCH ( _DateDifferenceCalucation, "Closed Date - Created Date", _Closed_Created, "Completed Date - Created Date", __Completed_Created, "Closed Date - Assigned Date", _Closed_Assigned, "Completed Date - Assigned Date", _Completed_Assigned, _Closed_Completed )Result:
Here I calculate the day differences between different date. You can change the Day to year, month, Hour and so on.
For more info to dax functions: Switch function Datediff function
You can download the pbix file from this link: Calculated Column's formula is based on a value in a column
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
You can't use the formula in columns, but you can use switch function like lbendlin 's reply to calculate date difference.
In addition to lbendlin 's reply, I build a table to have a test.
Build a calculated column:
Date Difference =
VAR _DateDifferenceCalucation = CALCULATE(MAX('Calculation'[Date Difference Calculation]),FILTER('Calculation','Calculation'[Country]=EARLIER('Table'[Country])))
VAR _Closed_Created =
DATEDIFF ( 'Table'[Created Date], 'Table'[Closed Date], DAY )
VAR _Closed_Assigned =
DATEDIFF ( 'Table'[Assigned Date], 'Table'[Closed Date], DAY )
VAR _Closed_Completed =
DATEDIFF ( 'Table'[Completed Date], 'Table'[Closed Date], DAY )
VAR _Completed_Assigned =
DATEDIFF ( 'Table'[Assigned Date], 'Table'[Completed Date], DAY )
VAR __Completed_Created =
DATEDIFF ( 'Table'[Created Date], 'Table'[Completed Date], DAY )
RETURN
SWITCH (
_DateDifferenceCalucation,
"Closed Date - Created Date", _Closed_Created,
"Completed Date - Created Date", __Completed_Created,
"Closed Date - Assigned Date", _Closed_Assigned,
"Completed Date - Assigned Date", _Completed_Assigned,
_Closed_Completed
)
Result:
Here I calculate the day differences between different date. You can change the Day to year, month, Hour and so on.
For more info to dax functions: Switch function Datediff function
You can download the pbix file from this link: Calculated Column's formula is based on a value in a column
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.