cancel
Showing results for 
Search instead for 
Did you mean: 
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

Accepted Solutions
Microsoft v-haibl-msft
Microsoft

Re: Subtract dates on same row

@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
Vvelarde Community Champion
Community Champion

Re: Subtract dates on same row

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




Lima - Peru
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!




Microsoft v-haibl-msft
Microsoft

Re: Subtract dates on same row

@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

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors