Forum Discussion
smithub
Helper I
3 years agoCalculate days
Hi all, I would like to calculate the number of days each application is at each stage. From above image 'Earliest FirstDate' column shows the first date that the application went into...
Anonymous
3 years agoNot applicable
Hi smithub ,
I create a sample to have a test.
Days Calculation =
VAR _SUMMARZIE =
SUMMARIZE (
ALLSELECTED ( 'Table' ),
'Table'[Case ID],
'Table'[Stage],
'Table'[Sort Order],
'Table'[Earliest FirstDate]
)
VAR _ADD1 =
ADDCOLUMNS (
_SUMMARZIE,
"DateDiff",
VAR _LINENEXT =
MINX (
FILTER (
_SUMMARZIE,
[Case ID] = EARLIER ( [Case ID] )
&& 'Table'[Sort Order] > EARLIER ( [Sort Order] )
),
[Earliest FirstDate]
)
RETURN
DATEDIFF ( [Earliest FirstDate], _LINENEXT, DAY )
)
RETURN
IF (
MAX ( 'Table'[Sort Order] )
= MAXX ( ALLEXCEPT ( 'Table', 'Table'[Case ID] ), 'Table'[Sort Order] ),
SUMX ( _ADD1, [DateDiff] ),
SUMX (
FILTER (
_ADD1,
[Case ID] = MAX ( 'Table'[Case ID] )
&& [Stage] = MAX ( 'Table'[Stage] )
),
[DateDiff]
)
)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
smithub
Helper I
3 years agoHi, thanks a mil for your reply.
Just a question on the first piece of code.
VAR _SUMMARZIE =
SUMMARIZE (
ALLSELECTED ( 'Table' ),
'Table'[Case ID],
'Table'[Stage],
'Table'[Sort Order],
'Table'[Earliest FirstDate]My columns are coming from different tables:
Table Column
Table 1 Case ID
Table 2 Stage
Table 3 Sort Order
Table 1 Earliest FirstDate
How can I put this int the code please?