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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Calculate days between dates in different tables

Can someone please provide me with assistance. I have 2 tables which are joined on a Project # and need to find the number of days between Created On Date  and Project Start Date. Below is an example of what I am looking to achive.

(Table 1 [Created On])   (Table 2 [Project Start Date])Desired Result
1/5/2022             5/5/2022

120

2/18/20223/1/202211

 

Thanks for any help!

 

1 ACCEPTED SOLUTION

Hi rohit_singh

 

Thanks for your help, but please check your solution suggetion .....

var _datediff = DATEDIFF('DatesBetween'[CREATED_ON],'DatesBetween'[PROJ_ST_DT],DAY)

 

Wont the DatesBetween'[CREATED_ON]  return a buggy table value ? 🤔

 

You need to wrap it in a SELETEDVALUE, MIN or MAX to get a scalar value.

See  method I suggested.

 

Many thanks 😎

 

View solution in original post

10 REPLIES 10
ziddmakk
New Member

To calculate the days between the "Created On" date from Table 1 and the "Project Start Date" from Table 2, assuming they are joined on a Project #, you can use a simple date difference formula in a database query or spreadsheet. For example, in SQL, you could write: SELECT DATEDIFF(t2.Project_Start_Date, t1.Created_On) AS Days_Between FROM Table1 t1 JOIN Table2 t2 ON t1.Project_Number = t2.Project_Number. For your specific example, this would yield 120 days between 1/5/2022 and 5/5/2022 (accounting for inclusive dates and a leap year), and 11 days between 2/18/2022 and 3/1/2022. In a spreadsheet like Excel, use =(Table2!Project_Start_Date - Table1!Created_On) and format the result as a number, giving you 120 and 11 respectively. Adjust based on your tool and whether you need inclusive or exclusive day counts.

speedramps
Super User
Super User

fromats your dates correctly eg dd/mm/yyyy depending on your region

 

create a  relationship from table1 project id to table2 project id 

 

create dax measure 

 
daysage =
DATEDIFF(
SELECTEDVALUE(Table1[CREATED_ON]),
SELECTEDVALUE(Table2[PROJ_ST_DT]),
DAY
)
 
create a table visua; and drag:-
table1 PROJ_NBR
table 1 CREATED_ON
table 2 PROJ_ST_DT
daysage 
 
please click thumbs up and accept as solution buttons. Thank you ! 😎
Anonymous
Not applicable

Table 1 Table 2 
PROJ_NBRCREATED_ON PROJ_NBRPROJ_ST_DTDesired Results
12341/5/2022 12345/5/2022120
68542/18/2022 68543/1/202211
85445/3/2022 8544 0

Hi @Anonymous ,

Please try creating a calculated column on your table as shown below :

Duration =

var _datediff = DATEDIFF('DatesBetween'[CREATED_ON],'DatesBetween'[PROJ_ST_DT],DAY)

return
if (isblank(_datediff), 0 , _datediff)

rohit_singh_0-1652727128927.png

This should give you the desired result.


Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊

Does this still work if the relationship between the tables is many to many? When I try to add a calculated column with DATEDIFF it wont search for the other table as the second variable.

Hi rohit_singh

 

Thanks for your help, but please check your solution suggetion .....

var _datediff = DATEDIFF('DatesBetween'[CREATED_ON],'DatesBetween'[PROJ_ST_DT],DAY)

 

Wont the DatesBetween'[CREATED_ON]  return a buggy table value ? 🤔

 

You need to wrap it in a SELETEDVALUE, MIN or MAX to get a scalar value.

See  method I suggested.

 

Many thanks 😎

 

Hi @speedramps ,

Thanks for your feedback. I have created a calculated column and not a measure so it will work as expected. 

Anonymous
Not applicable

The first one I created an excel spreadsheet when adding the details of my request and the last one was a copy of an external excel. If you let me know how to attach an excel document I will upload it.

You can copy excel cells and paste them into the chat as a table.

This is safer than sending excel files which can contain nasty malware

speedramps
Super User
Super User

provide example input tables as tables (not a screen shots, so we cam import then quickly create a solution)

 

 Thanks

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.