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
Ged
Helper I
Helper I

DATEDIFF - two tables with one-to-many and 'blanks'

Dear all

 

I've been scratching my head for quite a bit on this. 

In a nutshell:

  • Objective - building a 'time-to-delivery' view between Sales Orders and corresponding Delivery Notes at individual product level. 
    • If there is a delivery note date, my time to delivery is calculated as: Delivery Note Date minus Sales Order date
    • If there is no delivery note date yet (Sales Order has not yet been delivered), my time to delivery is TODAY() minus Sales Order date.
  • Sales Order table and Delivery Note table is a one-to-many relationship. Linked via Key (concatenated string of Sales Order ID & Sales Order Line ID)
  • Sales Order table has more records than Delivery Note table (there are new Sales Orders that do not have deliveries yet naturally).

I dont think I'm able to create a calculated column in either of the tables, reasons:

  • Cannot create a column in Delivery Note table because there are Sales Orders that have no Delivery Notes yet.
  • Cannot create a column in Sales Order Table because some Order lines can have multiple delivery notes with different dates (showed in the sample data).

I would need to use this 'time to delivery' figure in various visuals.

 

How can I best achieve this? 

 

I created some sample data that mimicks my actual model. 

Sample data + pbix can be found here. 

 

1 ACCEPTED SOLUTION
Ged
Helper I
Helper I

Just for anyone looking for a solution, I solved it with the Merge Query function by creating a merged table and a calculated column there. 

View solution in original post

1 REPLY 1
Ged
Helper I
Helper I

Just for anyone looking for a solution, I solved it with the Merge Query function by creating a merged table and a calculated column there. 

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.