Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Solved! Go to 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] ) )
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
@akhaliq7 , You can do that using a common dimension
This is an example for direct query but true for import mode too
Thats not what I am looking for.
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
12 | |
10 | |
6 |