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
Anonymous
Not applicable

Calculate number of months since ship date and action date.

Hi all,

 

So, I am trying to calculate the difference between two different date columns in two separate tables.

Essentially, I have 2 tables that look like this (sorry for the poor screenshot lol)

 

Example.png

 

So, I am trying to calculate the difference between these dates in terms of months. But I cannot figure out how to actually calculate it using DATEDIFF. I can't have a relationship between the two dates because they are completely different. I would think to create a new column within the shipped date table and use DATEDIFF(Shipped Date[Shipped Date], Action Date[List], MONTH) but it refuses to accept it, saying it cannot find Action Date[List] or that there needs to be a relationship between them. 

 

I would appreciate any help!

 

1 ACCEPTED SOLUTION
TeigeGao
Solution Sage
Solution Sage

Hi @Anonymous ,

In your scenario, it is not supported to create a relationship between two tables because they don't have a same column to create relationship, at least you need to have a id column or other.

If you want to calculate the DATEDIFF row by row, you can create an index column for two tables like below:

L57pnoNipF.gif

Then we can create a relationship between these two index column, after that we can create a calculated column using the following DAX query:

Column = CALCULATE(DATEDIFF(MIN(Table1[Shipped Date]),MIN(Table2[Action Date]),MONTH))

The result will like below:

PBIDesktop_verc93sKSL.png

Best Regards,

Teige

View solution in original post

3 REPLIES 3
TeigeGao
Solution Sage
Solution Sage

Hi @Anonymous ,

In your scenario, it is not supported to create a relationship between two tables because they don't have a same column to create relationship, at least you need to have a id column or other.

If you want to calculate the DATEDIFF row by row, you can create an index column for two tables like below:

L57pnoNipF.gif

Then we can create a relationship between these two index column, after that we can create a calculated column using the following DAX query:

Column = CALCULATE(DATEDIFF(MIN(Table1[Shipped Date]),MIN(Table2[Action Date]),MONTH))

The result will like below:

PBIDesktop_verc93sKSL.png

Best Regards,

Teige

Anonymous
Not applicable

That makes more sense. I have a string for each customer, am I not able to relate that between the two?

Anonymous
Not applicable

in your shipped date table, what date from the other table would you be looking to subtract? Seems like there should be a few more columns to each of these tables.

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.