Forum Discussion
Calculate difference between date group by columns
- Anonymous2 years ago
Hi Juju123
You can refer to the following solution.
1.Create a num measure to extract the num from operation code.
No = INT ( MID ( SELECTEDVALUE ( Table1[Operation code] ), SEARCH ( "E", SELECTEDVALUE ( Table1[Operation code] ),, BLANK () ) + 1, LEN ( SELECTEDVALUE ( Table1[Operation code] ) ) - SEARCH ( "E", SELECTEDVALUE ( Table1[Operation code] ),, BLANK () ) ) )2.Create a Rank measure
Rank = RANKX ( FILTER ( ALLSELECTED ( Table1 ), [Workflow number] IN VALUES ( Table1[Workflow number] ) && [Article] IN VALUES ( Table1[Article] ) ), [No], , ASC )3.Then calculate the differnce
Temps entre chaque operation = VAR a = [Rank] - 1 VAR _predate = MAXX ( FILTER ( ALLSELECTED ( Table1 ), [Workflow number] IN VALUES ( Table1[Workflow number] ) && [Article] IN VALUES ( Table1[Article] ) && [Rank] = a ), [Operation Date] ) RETURN IF ( DATEDIFF ( _predate, MAX ( Table1[Operation Date] ), DAY ) <> BLANK (), DATEDIFF ( _predate, MAX ( Table1[Operation Date] ), DAY ), 0 )Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi ryan_mayu ,
Thanks for your feedback.
I'm beignner on Power BI and I would like to understand what you have.
If I understand correctly, you first created an Index to sort the dates.
Secondly, do you calculate the difference between each operation for each Workflow, article, article designation and Operation code?
On the other hand, I don't understand why the new column is in date format instead of being in number format? Because the goal is to calculate the difference between each operation, we should therefore have numbers in this column unless I have not understood your process.
That's right ?
not sort the dates, just sort row orders. i don't think the calculation is following the date order.
You can change the data type to number format. However, what's the expected output for "05/11/2018 - 0" ? also be a number? That will be a very huge number.
So pls confirm what's the data type will be. you can either set it as a number or a date.
- Juju1232 years agoHelper III
Thank you for the explanations and I understand better what the "Index" column is for.
The result is to have the difference in days for each operation.
Example for the first operation the number of days will be 0 days. This is why I put 05/11/2018 - 0
For the second operation the calculation will be 05/11/2018 - 19/12/2018 and so on.Have I been clear ?
- ryan_mayu2 years agoSuper User