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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
yem19397
Regular Visitor

How to make a new column from two tables with relationship many to many

Hi All,

 

I want to make a new column "Handling Date" which is the date difference between OrderDate (from table A) and ShipDate (from table B). The relationship between table A and table B is many to many. How to do this?

 

I tried with:

 

Handling Date= DATEDIFF('B'[ShipDate],RELATED('A'[OrderDate]),DAY)
 
But it doesn't work.
 
Thanks,
 
Michael
3 REPLIES 3
johncolley
Solution Sage
Solution Sage

Hi @yem19397 , Can you provide more information on what doesn't work - there could be a number of issues causing this.

 

For example the order in which your formula is written is probably going to produce negative values as the shipping date is likely to be after the order date. 

 

Or the issues could be stemming from your many-to-many relationship (which should be avoided majority of the time). What fields is the relationship using? Are you able to create a 1 - Many relationship using something like an Order ID?

 

Hi John,

 

Thanks for your reply. 

 

I used Handling Date= DATEDIFF('A'[OrderDate],RELATED('B'[ShipDate]),DAY)

 

It also doesn't work.

 

The error message is:

 

The column 'B'[ShipDate]' either doesn't exist or doesn't have a relationship to any table available in the current context.

The relationship between A and B is many to many and cannot be changed to 1-many  or 1-1. The relationship between the two tables is linked based on Order ID. I think other function, in addition to related(), should also be used and involved.

 

Thanks,

Michael

Hi @yem19397 , Thanks for providing some more information. My first suggestion would be to try and remove the many-to-many relationship with a bridging table - see here: https://www.seerinteractive.com/blog/join-many-many-power-bi/ 

 

If you have to use many to many - related function won't work. You could try Lookupvalue as suggested here: https://community.powerbi.com/t5/Desktop/DATEDIFF-between-two-tables-many-to-many-relationship/td-p/...

 

Please provide some sample data if you require any further assistance.

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.