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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

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
tamerj1
Community Champion
Community Champion

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

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

tamerj1
Community Champion
Community Champion

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.