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,
Share data in a format that can be pasted in an MS Excel file.
Hi Ashish_Mathur ,
I create a csv file, it's ok for you ?
Workflow number;Article;Designation article;Operation code;Operation label;Operation date
WF0000000002;123456;STICK;OPE020;;05/11/2018
WF0000000002;123456;STICK;OPE070;;19/12/2018
WF0000000002;123456;STICK;OPE090;;15/11/2018
WF0000000002;123456;STICK;OPE099;;13/12/2018
WF0000000002;123456;STICK;OPE110;;07/12/2018
WF0000000002;123456;STICK;OPE140;;07/12/2018
WF0000000002;123456;STICK;OPE150;;07/12/2018
WF0000000002;741852;ON BOARD;OPE020;;01/03/2018
WF0000000002;741852;ON BOARD;OPE070;;05/06/2018
WF0000000002;741852;ON BOARD;OPE090;;10/09/2018
WF0000000002;741852;ON BOARD;OPE099;;13/09/2018
WF0000000002;741852;ON BOARD;OPE110;;20/09/2018
WF0000000002;741852;ON BOARD;OPE140;;25/10/2018
WF0000000002;741852;ON BOARD;OPE150;;30/10/2018
WF0000000002;741852;ON BOARD;OPE160;;05/11/2018
- Ashish_Mathur2 years agoSuper User
Write these calculated column formulas
Operation number = 1*(RIGHT(Data[Operation code],3))Previous date = CALCULATE(MAX(Data[Operation date]),FILTER(Data,Data[Workflow number]=EARLIER(Data[Workflow number])&&Data[Article]=EARLIER(Data[Article])&&Data[Designation article]=EARLIER(Data[Designation article])&&Data[Operation number]<EARLIER(Data[Operation number])))Difference = if(ISBLANK(Data[Previous date]),BLANK(),1*(Data[Operation date]-Data[Previous date]))Hope this helps.
- Juju1232 years agoHelper III
Hi Ashish_Mathur ,
Thanks for your solution.
I test it and i'm blocked in step two.
I'm in DirectQuery Mode and i have an error when i use EARLIER in my measure. I have this error when i create a column with EARLIER : EARLIEST refers to an earlier row context that does not exist
I create a new measure and i try to replace function EARLIER by SELECTEDVALUE but it's doesent work :
Previous date = CALCULATE(MAX(CAGC_ADVL_INDICATEURS_ETAPES_WF_REP[WF - Date fin reelle]),FILTER('CAGC_ADVL_INDICATEURS_ETAPES_WF_REP',CAGC_ADVL_INDICATEURS_ETAPES_WF_REP[WF - Numéro du workflow]=SELECTEDVALUE('CAGC_ADVL_INDICATEURS_ETAPES_WF_REP'[WF - Numéro du workflow])&&CAGC_ADVL_INDICATEURS_ETAPES_WF_REP[Designation article]=SELECTEDVALUE('CAGC_ADVL_INDICATEURS_ETAPES_WF_REP'[Designation article])&&CAGC_ADVL_INDICATEURS_ETAPES_WF_REP[Numero article externe]=SELECTEDVALUE('CAGC_ADVL_INDICATEURS_ETAPES_WF_REP'[Numero article externe])&&CAGC_ADVL_INDICATEURS_ETAPES_WF_REP[OPERATION NUMBER]<SELECTEDVALUE('CAGC_ADVL_INDICATEURS_ETAPES_WF_REP'[OPERATION NUMBER])))- Ashish_Mathur2 years agoSuper User
Mine are calculated column formulas - not measures.