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
aadass
Frequent Visitor

Problem to use DATEDIFF function between two dates which located in two not directly related tables

DATEDIFF.JPG

Problem to use DATEDIFF function between two dates which located in two but not directly related tables.

Task: Stock.Registration_Date - Invoices.InvoiceDate

 

Formula: NeedDate= DATEDIFF([Registration_Date],RELATED(Invoices[InvoiceDate]),WEEK)

Err: The column 'Invoices[InvoiceDate]' either doesn't exist or doesn't have a relationship to any table available in the current context

 

Comments: There two tables "Stock" and "Invoice" - they are related through table in between "InvoiceLines".

Thank you

1 ACCEPTED SOLUTION

@aadass,

 

Given the relationship, you may use RELATEDTABLE Function.

MAXX ( RELATEDTABLE ( Invoices ), Invoices[InvoiceDate] )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @aadass

 

Are you trying to create a new column in the 'Stock' table or the 'InvoiceLines' table?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

For now  "Stock" table..  - where i am trying to create new Measure. (In the future this New Measure should be used in

report(Visualization)

but i mentioned those three tbls because tbl InvoiceLines is in between two Main tbls "Stock" and "Invoices"

I need one field from Stock and one from Invoices (they are not linked directly - but only through InvoiceLines )

 

tnx

Angelika

 

@aadass,

 

Given the relationship, you may use RELATEDTABLE Function.

MAXX ( RELATEDTABLE ( Invoices ), Invoices[InvoiceDate] )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sam,

i think it solved my issue:

 

Weeks in stock = DATEDIFF([Registration_Date],MAXX(RELATEDTABLE(Invoices),Invoices[InvoiceDate]),WEEK)

 

I would never thought that MAXX  can act as a little liason between "unrelated" tables 

 

 

Thank you much

 

Angelika

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.