The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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/2022 | 3/1/2022 | 11 |
Thanks for any help!
Solved! Go to 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 😎
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.
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
Table 1 | Table 2 | ||||
PROJ_NBR | CREATED_ON | PROJ_NBR | PROJ_ST_DT | Desired Results | |
1234 | 1/5/2022 | 1234 | 5/5/2022 | 120 | |
6854 | 2/18/2022 | 6854 | 3/1/2022 | 11 | |
8544 | 5/3/2022 | 8544 | 0 |
Hi @Anonymous ,
Please try creating a calculated column on your table as shown below :
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.
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
provide example input tables as tables (not a screen shots, so we cam import then quickly create a solution)
Thanks
User | Count |
---|---|
86 | |
86 | |
36 | |
35 | |
34 |
User | Count |
---|---|
94 | |
79 | |
63 | |
55 | |
52 |