Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Broly
Frequent Visitor

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!
1 ACCEPTED SOLUTION
HoangHugo
Solution Specialist
Solution Specialist

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

View solution in original post

5 REPLIES 5
HoangHugo
Solution Specialist
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))

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

Broly_1-1665113067940.png

 

HoangHugo
Solution Specialist
Solution Specialist

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

amitchandak
Super User
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

Broly_0-1665112931401.png

I have this error

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.