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
JOO13
Resolver I
Resolver I

Using RELATED () with Date range conditions and many-to-many relationship

Hi All, 

 

I'm trying to lookup some information from Table 1 below to Table 2. 

 

Table 1 - Sales info: 

CustomerProductSales Contract Start Date Contract End Date Fiscal Year of Order Date 
AZ1001/1/201812/31/20182018
AY2001/1/201812/31/20182018
AZ2004/1/201812/31/20182018
BY4009/1/20184/1/20192018
BY3001/1/20199/30/20202019
AZ15010/1/20194/1/20202019

 

Table2 - Issues Info: 

Customer Product Total No. of IssuesIssue Date 
AZ21/1/2018
AY51/1/2018
AZ35/4/2018
BY712/30/2018
BY38/1/2020
AZ211/23/2019

 

Ultimately, we would like to have Table 2 looks like below with additional column lookup-ed from Table 1 (Fiscal Year of Order Date):

Customer Product Total No. of IssuesIssue Date Fiscal Year of Issue Date 
AZ21/1/20182018
AY51/1/20182018
AZ35/4/20182018
BY712/30/20182018
BY38/1/20202019
AZ211/23/20192019

 

'Fiscal Year of Order Date' is match in Table 2 if and only if the Issue Date falls between the 'Contract Start Date' and 'Contract End Date'. 

 

I've tried to create additional column "Key" by concatenate "Customer" & "Product". Then I've linked them up between both tables as Many-to-many relationship. 

 

Below are the expressions that I have tried out by using the function RELATED(), 

 

Lookup = if(Table2[Key]<=related('Table1'[Key]),if(Table2[Issue Date].[Date]<=related('Table1'[Contract End Date].[Date]),if(Table2[Issue Date].[Date]>=related('Table1'[Contract Start Date]),related('Table1'[Fiscal Year of Issue Date]),"")))
 
but with below errors: 
"The column 'Table1'[Fiscal Year of Issue Date] either doesnt exist or doesn't have a relationship to any table available in the current context"
 
Hopefully anyone could shed some light here on what's wrong. Any other proposals are always welcome as well. 
 
Thank you. 
1 ACCEPTED SOLUTION

Thank you! @Anonymous 
This works well with slight modifications per below: 

 

Column =

VAR Prod = 'Issues Info'[Product]
VAR Cust = 'Sales Info'[Customer]

VAR _issue = 'Issues Info'[Issue Date ]
VAR _result = CALCULATE(MAX('Sales Info'[Fiscal Year of Order Date ]),FILTER('Sales Info','Sales Info'[Contract Start Date ]<=_issue && 'Sales Info'[Contract End Date ]>=_issue && 'Sales Info'[Product] = Prod &&'Sales Info'[Customer]= Cust))
RETURN _result

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@JOO13 Create this calculated column in Issue Info table 

Column = 
VAR _issue = 'Issues Info'[Issue Date ]
VAR _result = CALCULATE(MAX('Sales Info'[Fiscal Year of Order Date ]),FILTER('Sales Info','Sales Info'[Contract Start Date ]<=_issue && 'Sales Info'[Contract End Date ]>=_issue && 'Sales Info'[Product] = 'Issues Info'[Product ]&&'Sales Info'[Customer]='Issues Info'[Customer ]))
RETURN _result

and check if it works for you 

Thank you! @Anonymous 
This works well with slight modifications per below: 

 

Column =

VAR Prod = 'Issues Info'[Product]
VAR Cust = 'Sales Info'[Customer]

VAR _issue = 'Issues Info'[Issue Date ]
VAR _result = CALCULATE(MAX('Sales Info'[Fiscal Year of Order Date ]),FILTER('Sales Info','Sales Info'[Contract Start Date ]<=_issue && 'Sales Info'[Contract End Date ]>=_issue && 'Sales Info'[Product] = Prod &&'Sales Info'[Customer]= Cust))
RETURN _result

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.