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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.