Forum Discussion

Broly's avatar
Broly
Frequent Visitor
3 years ago
Solved

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 :

idclose date
11-Jan
22-Feb
32-Mar
41-Apr
51-May

An item schedule has an line Item ID, opportunity ID and schedule dates :

line item IDopportunity idschedule date 
112-Jan
214-Sep
311-Dec
414-Nov
514-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 :

idclose dateclose date - schedule date < 1 month ?
11-Jan2
22-Feb 
32-Mar 
41-Apr 
51-May 

 

when I try this formula: 

column = CALCULATE(COUNT('Line Item Schedule'[Id]),DATEDIFF(Opportunity[CloseDate],'Line Item Schedule'[ScheduleDate],DAY)<30)
 
I have an error saying "the expression contains columns from multiple tables, but only columns from a single table can be used in a true/false expressions that is used as a table filter expression"
 
 
I would appreciate your help,
 
Thanks!

5 Replies

  • 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

  • HoangHugo's avatar
    HoangHugo
    Icon for Solution Specialist rankSolution 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))

    • Broly's avatar
      Broly
      Frequent Visitor

      Hey thanks for your help, I can't put close date in the ealier formula since its a column:

       

      • HoangHugo's avatar
        HoangHugo
        Icon for Solution Specialist rankSolution Specialist

        sorry, it shoule be EARLIER([close date])-30