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
game1
Helper II
Helper II

Subtract the 3 dates from different tables

I have Table2[dateBefore], Table1[dateBegin] and Table1[dateEnd].

So, I need to subtract the 3 dates, so I can have the result in DAYS:  so something like Table2[dateBefore] - Table1[dateEnd] - Table1[dateBegin] 

So, I create a new coloumn call DatesDiff = DATEDIFF(Table2[dateBefore], Table1[dateBegin], DAY) + DATEDIFF(Table2[dateBefore], Table1[dateEnd], DAY)

But the new coloumn call DatesDiff is create in Table1, so I can have acces to Table2[dateBefore].

How can I do if I want to subtract column from differents tables?  I need to have an ID common to the 2 tables to do that?

Can I do that using join?

Please, give complete answer.

1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @game1 ,

 

According to your description, you can use the SELECTEDVALUE () function to realize that you want to subtract columns from different tables,
Here is an example:
My Sample:
Table1:

vweiyan1msft_4-1704190265419.png

Table2:

vweiyan1msft_5-1704190296127.png

The formula is as follows.

DatesDiff =
DATEDIFF ( SELECTEDVALUE ( Table2[dateBefore] ), Table1[dateBegin], DAY )
    + DATEDIFF ( SELECTEDVALUE ( Table2[dateBefore] ), Table1[dateEnd], DAY )

Result is as below.

vweiyan1msft_6-1704190347189.png

 

Best Regards,
Yulia Yan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-weiyan1-msft
Community Support
Community Support

Hi @game1 ,

 

According to your description, you can use the SELECTEDVALUE () function to realize that you want to subtract columns from different tables,
Here is an example:
My Sample:
Table1:

vweiyan1msft_4-1704190265419.png

Table2:

vweiyan1msft_5-1704190296127.png

The formula is as follows.

DatesDiff =
DATEDIFF ( SELECTEDVALUE ( Table2[dateBefore] ), Table1[dateBegin], DAY )
    + DATEDIFF ( SELECTEDVALUE ( Table2[dateBefore] ), Table1[dateEnd], DAY )

Result is as below.

vweiyan1msft_6-1704190347189.png

 

Best Regards,
Yulia Yan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.