Forum Discussion
Compare 2 dates in 2 different tables
Hi,
I have a tables with Salesforce opportunities and an other one with scheduled dates delivery for each products that an opportunity has.
An opportunity has an ID and a closing date :
| id | close date |
| 1 | 1-Jan |
| 2 | 2-Feb |
| 3 | 2-Mar |
| 4 | 1-Apr |
| 5 | 1-May |
An item schedule has an line Item ID, opportunity ID and schedule dates :
| line item ID | opportunity id | schedule date |
| 1 | 1 | 2-Jan |
| 2 | 1 | 4-Sep |
| 3 | 1 | 1-Dec |
| 4 | 1 | 4-Nov |
| 5 | 1 | 4-Jan |
There is a relationship between opportunity table and product table and a relationship between product and line item table but not a direct relationship between opportunity and line item.
for each opportunity I want to count the number of lineItem when the line item schedule date minus the opportunity close date is < to 1 month.
For example in this case, opportunity 1 will return 2 since the first line Item (2 jan - 1 jan = 1) and the 5th line item (4 jan - 1 jan = 3) match the case :
| id | close date | close date - schedule date < 1 month ? |
| 1 | 1-Jan | 2 |
| 2 | 2-Feb | |
| 3 | 2-Mar | |
| 4 | 1-Apr | |
| 5 | 1-May |
when I try this formula:
sorry, it shoule be EARLIER([close date])-30
5 Replies
- amitchandak
Super User
Broly , if relation is there then
column = CALCULATE(COUNT('Line Item Schedule'[Id]),DATEDIFF(Opportunity[CloseDate],maxx(relatedtable('Line Item Schedule'),'Line Item Schedule') [ScheduleDate],DAY)<30)
or
column = CALCULATE(COUNT('Line Item Schedule'[Id]),DATEDIFF(Opportunity[CloseDate],Minx(relatedtable('Line Item Schedule'),'Line Item Schedule') [ScheduleDate],DAY)<30)
The above calculation should also work as a measure
refer 4 ways to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8- BrolyFrequent Visitor
I have this error
- HoangHugo
Solution Specialist
Hi, try this
column = CALCULATE(COUNT('Line Item Schedule'[Id]),'Line Item Schedule'[ScheduleDate]>EARLIER([Close Date]-30)
or
colum = COUNTROW(FILTER('Line Item Schedule,,'Line Item Schedule'[ScheduleDate]>EARLIER([Close Date]-30))