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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
chonchar
Helper V
Helper V

Days difference between unrelated tables

Hello. I have searched the forums and cannot find a solution that works for my case. Please take a look at the problem below. I promise to send kudos and accept solutions. 

 

I have two tables that I need to calculate the difference between and they are related through a third table (see entity relationship below). 

 

chonchar_0-1715794543984.png

I need to calculate the days difference between tables 1 and 2. The key for each of these tables is in table 3 (that is the only way I can connect them). Below is  my expected output. 

 

chonchar_1-1715794623921.png

 

I would appreciate any help or solutions you could offer. 

@parry2k @Ritaf1983 @amitchandak @Ashish_Mathur  if you're available. 

1 ACCEPTED SOLUTION
v-xiandat-msft
Community Support
Community Support

Hi @chonchar ,

Thank you for @Ashish_Mathur  answer.

Below is my table1:

vxiandatmsft_0-1715826976003.png

Below is my table2:

vxiandatmsft_1-1715826995842.png

Below is my table3:

vxiandatmsft_2-1715827007374.png

The following DAX might work for you:

 

Days Difference1 = 
VAR DateFromTable1 = CALCULATE(MINX('Table1',Table1[approved date]), RELATEDTABLE('Table'))
VAR DateFromTable2 = CALCULATE(MAX(Table2[Creation date]), RELATEDTABLE('Table'))
RETURN  
 DATEDIFF(DateFromTable1, DateFromTable2, DAY)

 

The final output is shown in the following figure:

vxiandatmsft_3-1715827057261.png

The reason for the incorrect values is mainly because the relationships are not known how they are paired, please send your relationship pairing chart in detail as the correct pairing of the relationships can make a big difference in the results.

Best Regards,

Xianda Tang

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

3 REPLIES 3
v-xiandat-msft
Community Support
Community Support

Hi @chonchar ,

Thank you for @Ashish_Mathur  answer.

Below is my table1:

vxiandatmsft_0-1715826976003.png

Below is my table2:

vxiandatmsft_1-1715826995842.png

Below is my table3:

vxiandatmsft_2-1715827007374.png

The following DAX might work for you:

 

Days Difference1 = 
VAR DateFromTable1 = CALCULATE(MINX('Table1',Table1[approved date]), RELATEDTABLE('Table'))
VAR DateFromTable2 = CALCULATE(MAX(Table2[Creation date]), RELATEDTABLE('Table'))
RETURN  
 DATEDIFF(DateFromTable1, DateFromTable2, DAY)

 

The final output is shown in the following figure:

vxiandatmsft_3-1715827057261.png

The reason for the incorrect values is mainly because the relationships are not known how they are paired, please send your relationship pairing chart in detail as the correct pairing of the relationships can make a big difference in the results.

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-xiandat-msft this works perfectly. Thank you very much. 

Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.  Show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors