Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
akhaliq7
Post Prodigy
Post Prodigy

Need to subtract two date columns that are in different tables/queries

Hi I have very basic knowledge of dax but need to subtract two date fields that are stored in two different queries/tables. A calculated column is what I want to use as I want it to be part of my data model. 

 

Here is an example of it in SQL:

Trunc(table1.datecolumn) - Trunc(table2.datecolumn)

 

I want to store the column in table2 thanks

1 ACCEPTED SOLUTION

Then if the calculated column is in table2 then you can use RELATED to grap the date value from table1 so you can just sbtract Table2[Date] - RELATED ( Table1[Date] )
However if the calculated column is in table1 the you need to provide some kind of aggregation like MAX or MIN. Example: Table1[Date] - MAX ( RELATEDTABLE ( Table2[Date] ) )

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi Khalid
Can you provide more details about your tables? Any common or related columns between the two tables? Do both tables have the same number of rows? 

table2 is a fact table and table1 a dim table therefore they don't have the same number of rows, saleID is used to connect both tables

Then if the calculated column is in table2 then you can use RELATED to grap the date value from table1 so you can just sbtract Table2[Date] - RELATED ( Table1[Date] )
However if the calculated column is in table1 the you need to provide some kind of aggregation like MAX or MIN. Example: Table1[Date] - MAX ( RELATEDTABLE ( Table2[Date] ) )

That makes sense with the aggregation happening only in the dimension table. Thanks also I got the result I was looking for.

Thanks for your help

amitchandak
Super User
Super User

@akhaliq7 , You can do that using a common dimension

This is an example for direct query but true for import mode too

https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thats not what I am looking for. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.