Forum Discussion
Calculate 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 each category. The categories listed above have subcategories, that's why there are more than one date for each category. I want to calculate the number of days between the first date of each category. You will seen a summary for Case ID showing first dates for each category.
For example I want to show:
'Post AIP- Pre App' days = ('Apps in Preparation' minus 'Post AIP- Pre App')
'Apps in Preparation' days = ('Apps With Credit' minus 'Apps in Preparation')
'Apps With Credit' days = ('Drawdowns - Apps With Credit')
'Drawdowns' = Total of all category days OR ('Drawdowns' minus 'Apps in Preparation')
Please note 'Sort Order' column is from a different tabel than the rest. See below.
| Table | Column |
| Status Activity | Case ID |
| Status Activity | Stage |
| Stage Order | Sort Order |
| Status Activity | Status Date |
| Status Activity | Earliest FirstDate |
Appreciate any help on this.
Thanks all.
5 Replies
- Greg_DecklerCommunity Champion
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.- smithubHelper 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
- AnonymousNot 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.
- Syndicate_AdminAdministrator
To solve this correctly in Power BI, create a new summary table with one row for each Customer_ID using this DAX formula:
CustomerDays = SUMMARIZE(Tabla, Tabla[Customer_ID], "Dias", DATEDIFF(MIN(Tabla[Date_start]), MAX(Tabla[Date_end]), DAY))This will correctly calculate the days between the first and last date per customer. You can then do sums and averages on this new table (CustomerDays) in your visuals to get the correct values.