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
Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.
Best Regards,
Rico Zhou
- Anonymous6 years agoNot applicable
I get the solution but I am having 2nd thoughts on that one as I am expecting that there would be hundreds of different calculations and doing that method will require me to input all the calculations. I was thinking more of using the Expression.evaluate()
- lbendlin6 years ago
Super User
Yes, go do that. Have a table with country, date A and date B column names, and then use Expression.Evaluate() to run the dynamic formula. Column names need to be encapsulated in brackets (eg [Created Date]) which makes your original format less usable.