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

Calculate difference between two date/time values from Two diffrent tables?

I have two table and one table has start date and another table has end date. I want difference between two dates.

 

I tried : DATEDIFF(<start_date>, <end_date>, <interval>) in column and Measure but still having problems

 

Table 1:

WoSdate
101/01/2016
202/01/2016
303/01/2016
404/01/2016
505/01/2016
606/01/2016
707/01/2016
808/01/2016
909/01/2016
1010/01/2016

 

Table 2:

WoEdate
101/02/2016
202/02/2016
303/02/2016
404/02/2016
505/02/2016
606/02/2016
707/02/2016
808/02/2016
909/02/2016
1010/02/2016

 

I want output something like below,

WoSdateEdateDiff
101/01/201601/02/201631
202/01/201602/02/201631
303/01/201603/02/201631
404/01/201604/02/201631
505/01/201605/02/201631
606/01/201606/02/201631
707/01/201607/02/201631
808/01/201608/02/201631
909/01/201609/02/201631
1010/01/201610/02/201631
5 REPLIES 5
v-sihou-msft
Employee
Employee

@vishalbaldania

 

I assume you have built the relationship between two tables already. You can create a column like below:

 

Diff = 1*('End'[EndDate]-RELATED('Start'[StartDate]))

4444.PNG

 

 

Regards,

Thank you Simon_Hou-MSFT  but in my original data have some blanks in start date column and end date column. so i want there "Not Applicable". is it possible, if yes how?

Table Relationship  (LYN - Work order ID)Table Relationship (LYN - Work order ID)Both tables data insert in a tableBoth tables data insert in a tableColumn SelectedColumn SelectedSimon_Hou-MSFT

 

Here is my original data screenshot. I have two tables - QOrdersAwaitingPart and RPT_ISSUED_PARTS. The tables connected with each other (relationship) * to 1.

 

QOrdersAwaitingPart table does not have unique column that's why I created unique column using measure which is called LYN. and RPT_ISSUED_PARTS table has unique column which called Work Order ID.

 

LYN and WorkorderID column combination pf Location-Year-WorkorderNumber.

 

Now, QOrdersAwaitingPart has start date which is called required date and RPT_ISSUED_PARTS have end date which is called issue date.

I want difference between both dates.

 

Please find attached images of data and relationship.

I tried it your method but I have having error please check in image

4.PNG

@vishalbaldania

 

If there's blank values for both start date and end date, you need to apply IF statement for the calculation like:

 

=
IF (
    'End'[EndDate] <> BLANK ()
        && RELATED ( 'Start'[StartDate] ) <> BLANK (),
    Diff
        = 1
            * ( 'End'[EndDate] - RELATED ( 'Start'[StartDate] ) ),
    BLANK ()
)

Regards,

 

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.