Forum Discussion
Anonymous
5 years agoNot applicable
Date Difference between dates from multiple tables
HI, I have 2 tables ( Orders, Tasks) with relationship Many-to-Many and Single Direction Filter, from Tasks=>Orders. I need to calculate the difference between Order Date and the Task date. I...
- 5 years ago
Hi Anonymous,
First create 3 slicer tables as below:
ID slicer = VALUES('Tasks Table'[User ID])Product slicer = VALUES('Orders Table'[Product])Type slicer = VALUES('Tasks Table'[Task Type])Then create 4 measures as below:
_Product = CALCULATE(MAX('Orders Table'[Product]),'Orders Table'[Product] in FILTERS('Product slicer'[Product]))_User ID = CALCULATE(MAX('Orders Table'[User ID]),'Orders Table'[User ID] in FILTERS('ID slicer'[User ID]))_Task date = CALCULATE(MAX('Tasks Table'[Task Date]),FILTER('Tasks Table','Tasks Table'[User ID]=[_User ID]&&'Tasks Table'[Task Type] in FILTERS('Type slicer'[Task Type])))_Diff = var _diff= DATEDIFF([_Task date],MAX('Orders Table'[Order Date]),DAY) Return IF(_diff<=1,_diff&" day",_diff&" days")And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
Anonymous
5 years agoNot applicable
v-kelly-msft as the data has the filters, basically 5268910 is excluded by the filter, therefore, the result will contain blank values for date diff.
v-kelly-msft
5 years agoCommunity Support
Hi Anonymous,
First create 3 slicer tables as below:
ID slicer = VALUES('Tasks Table'[User ID])Product slicer = VALUES('Orders Table'[Product])Type slicer = VALUES('Tasks Table'[Task Type])
Then create 4 measures as below:
_Product = CALCULATE(MAX('Orders Table'[Product]),'Orders Table'[Product] in FILTERS('Product slicer'[Product]))_User ID = CALCULATE(MAX('Orders Table'[User ID]),'Orders Table'[User ID] in FILTERS('ID slicer'[User ID]))_Task date = CALCULATE(MAX('Tasks Table'[Task Date]),FILTER('Tasks Table','Tasks Table'[User ID]=[_User ID]&&'Tasks Table'[Task Type] in FILTERS('Type slicer'[Task Type])))_Diff =
var _diff= DATEDIFF([_Task date],MAX('Orders Table'[Order Date]),DAY)
Return
IF(_diff<=1,_diff&" day",_diff&" days")
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!