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
PeterG1
Frequent Visitor

Subtract dates on same row

Hi, I am new to Power BI.

 

I like to subtract two dates from eachother, that is a result from a relationship. It is like this.

 

table1.Date1         table2.Date2

1-1-2016               5-1-2016

5-2-2015               10-2-2016

 

Any idea how I get from the first row: 4(days) and the second row 5(days) as answer?

 

I have tried quiet some things but i get always problems in PowerBi row, where I enter the measure formula.

 

Your help is appreciated.

Peter

1 ACCEPTED SOLUTION
v-haibl-msft
Employee
Employee

@PeterG1

 

If you do not have the key column, we can add index column for both of tables and create relationship between them.

Subtract dates on same row_1.jpg

 

Then create a column in Table1 with following formula.

Subtract = 
IF (
    Table1[Date1] < RELATED ( Table2[Date2] ),
    DATEDIFF ( Table1[Date1], RELATED ( Table2[Date2] ), DAY ),
    DATEDIFF ( RELATED ( Table2[Date2] ), Table1[Date1], DAY )
)

Subtract dates on same row_2.jpg

 

Best Regards,

Herbert

View solution in original post

2 REPLIES 2
v-haibl-msft
Employee
Employee

@PeterG1

 

If you do not have the key column, we can add index column for both of tables and create relationship between them.

Subtract dates on same row_1.jpg

 

Then create a column in Table1 with following formula.

Subtract = 
IF (
    Table1[Date1] < RELATED ( Table2[Date2] ),
    DATEDIFF ( Table1[Date1], RELATED ( Table2[Date2] ), DAY ),
    DATEDIFF ( RELATED ( Table2[Date2] ), Table1[Date1], DAY )
)

Subtract dates on same row_2.jpg

 

Best Regards,

Herbert

Vvelarde
Community Champion
Community Champion

What is the key columns of the relationship between this 2 tables?




Lima - Peru

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.