Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello Profis,
i need your help to create a measure to subtract two dates in days, which located in tabels no realtet between them.
Please find the screen shot maybe help you to solve my issue. In addtion i want to create this measure in Fact_SalesOrderLine as you see in the Pic.
Please if you need more infos, don't hesitate to contect me.
Thanks in Advance.
Solved! Go to Solution.
Hi @Talal141218 ,
According to your description, after you arrive at the results, there may be data mismatches in the results, or the calculated values do not make logical sense, I try to reproduce your problem with some sample data, I hope to provide some ideas for the problems you encountered!
My sample data is calculating the difference between the date of each sales order and the date of the latest purchase order, and in the case where I am using the error code , although the value is returned, there is a logic error, as detailed below:
Order corresponds to multiple Purch values, and since we don't have a relationship, we need the other columns to help us make sure that there are no duplicate values, and we can get the correct value.
DateDiffMeasure =
VAR OrderDate = MAX(Sales[OrderDate])
VAR ClosestPurchaseDate =
CALCULATE(
MIN(Purch[PurchaseDate]),
FILTER(
Purch,
Purch[PurchaseDate] <= OrderDate // Ensure that the purchase date is before the order date
&& Purch[Index] =MAX('Sales'[OrderID]) // Ensure that each order is uniquely matched
),
TOPN(1, Purch, Purch[PurchaseDate], DESC) // Get the most recent PurchaseDate
)
RETURN
IF(
NOT(ISBLANK(ClosestPurchaseDate)),
ABS(DATEDIFF(OrderDate, ClosestPurchaseDate, DAY)),
BLANK()
)
If you still have questions you can check out my pbix, I hope my answer can further answer your questions and I would be honored if I can solve your problem!
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hello,
You can calculate the dates you want to compare in variables and then place them in datediff.
e.g. Here I have a custom condition that date2 needs to be in year 2023, date1 has no conditions:
The tables are not related. You can add whatever conditions you need in the variable calculations (e.g. id needs to be some specific id).
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
Proud to be a Super User!
Hello,
Firstful thanks alot for your response,and i have results now but those are neither corresponding nor logic.
Hi @Talal141218 ,
According to your description, after you arrive at the results, there may be data mismatches in the results, or the calculated values do not make logical sense, I try to reproduce your problem with some sample data, I hope to provide some ideas for the problems you encountered!
My sample data is calculating the difference between the date of each sales order and the date of the latest purchase order, and in the case where I am using the error code , although the value is returned, there is a logic error, as detailed below:
Order corresponds to multiple Purch values, and since we don't have a relationship, we need the other columns to help us make sure that there are no duplicate values, and we can get the correct value.
DateDiffMeasure =
VAR OrderDate = MAX(Sales[OrderDate])
VAR ClosestPurchaseDate =
CALCULATE(
MIN(Purch[PurchaseDate]),
FILTER(
Purch,
Purch[PurchaseDate] <= OrderDate // Ensure that the purchase date is before the order date
&& Purch[Index] =MAX('Sales'[OrderID]) // Ensure that each order is uniquely matched
),
TOPN(1, Purch, Purch[PurchaseDate], DESC) // Get the most recent PurchaseDate
)
RETURN
IF(
NOT(ISBLANK(ClosestPurchaseDate)),
ABS(DATEDIFF(OrderDate, ClosestPurchaseDate, DAY)),
BLANK()
)
If you still have questions you can check out my pbix, I hope my answer can further answer your questions and I would be honored if I can solve your problem!
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
16 | |
15 | |
14 | |
12 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
9 |