Forum Discussion
Calculate days
smithub Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
- smithub3 years agoHelper I
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
- Anonymous2 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 ZhouIf 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?