Forum Discussion
Calculate days
Hi Greg,
Thanks for your reply.
The sample data is in the first table above. There are a number of dates at each stage. I've created a measure that identifies the first date of each category. You will see the column called 'Earlies FirstDate'.
I want to know how long the case has been at each stage using the first date of each stage.
| Line | Stage | Earliest FirstDate | Days | Days Calculation |
| 1 | Post AIP - Pre APP | 15/03/2023 | 0 | Line 2 minus 1 |
| 2 | Apps in Preparation | 15/03/2023 | 19 | Line 3 minus 2 |
| 3 | App with Credit | 03/04/2023 | 12 | Line 4 minus 3 |
| 4 | With CMO | 15/04/2023 | 19 | Line 5 minus 4 |
| 5 | Drawdown | 04/05/2023 | 50 | Sum of line 1 to 4 |
The table I'm using in Power BI is the first one with the columns:
Case ID
Stage
Sort Order
Status Date
Earliest FirstDate
Note also - Status source table is different to the others. I've included table view above.
Hope you understand this.
Thanks
Hubert
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.
- smithub2 years agoHelper I
Hi, 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?