Forum Discussion
Average date difference between two dates in same column
- 6 years ago
Hi Anonymous
Sorry for replying late.
Please create measures
lastmonth = CALCULATE(MAX('date'[year-month]),FILTER(ALLSELECTED('Table'),'Table'[CustomerID]=MAX('Table'[CustomerID]))) measure in days = VAR days1 = CALCULATE ( SUM ( 'date'[days_m] ), VALUES ( 'date'[year-month] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[CustomerID] = MAX ( 'Table'[CustomerID] ) ) ) RETURN IF ( [lastmonth] = MAX ( 'date'[year-month] ) && [lastmonth] <> BLANK (), MAX ( 'date'[days_m] ) / 2, days1 ) each days = SUMX(FILTER(ALLSELECTED('Table'),'Table'[CustomerID]=MAX('Table'[CustomerID])),[measure in days]) average dyas = SUMX(ALLSELECTED('Table'),[measure in days])/2The date table used above
date = ADDCOLUMNS ( CALENDARAUTO (), "year", YEAR ( [Date] ), "month", MONTH ( [Date] ), "year-month", FORMAT ( [Date], "yyyy-mm" ) ) add a column in date table days_m = CALCULATE(COUNT('date'[Date]),ALLEXCEPT('date','date'[year-month]))Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - 6 years ago
Hi Anonymous
Is this ok?
lastmonth = CALCULATE ( MAX ( 'date'[year-month] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[CustomerID] = MAX ( 'Table'[CustomerID] ) && 'Table'[country] = MAX ( 'Table'[country] ) ) ) measure in days = VAR days1 = CALCULATE ( SUM ( 'date'[days_m] ), VALUES ( 'date'[year-month] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[CustomerID] = MAX ( 'Table'[CustomerID] ) && 'Table'[country] = MAX ( 'Table'[country] ) ) ) RETURN IF ( [lastmonth] = MAX ( 'date'[year-month] ) && [lastmonth] <> BLANK (), MAX ( 'date'[days_m] ) / 2, days1 ) each days = SUMX ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[CustomerID] = MAX ( 'Table'[CustomerID] ) && 'Table'[country] = MAX ( 'Table'[country] ) ), [measure in days] ) total eachdays = IF ( ISINSCOPE ( 'Table'[CustomerID] ), [each days], AVERAGEX ( SUMMARIZE ( 'Table', 'Table'[CustomerID], "m", [each days] ), [m] ) )Best Regards
Maggie
Hi Anonymous
For customer 2, he has only one date 2020/2/1,
for customer 3, he has a period from 2020/5/1-2020/6/1,
why the "waiting time in days" for them is 14.5, 46,
For customer 4, if we say he has a period from 2018/1/1-2019/7/1, then his "waiting time in days" should be 500+days.
Please explain the calculation rule.
Best Regards
Maggie
- Anonymous6 years agoNot applicable
Thanks for your reply.
Customer 2 has only one date, because that customer wasn't anymore on the waiting list for 2020/3/1. But since we don't know when that customer wasn't anymore on the list on February, the number of waiting days is 14.5. This is our best approach/estimation we can make (29 days this year in Febrary, so 0.5 = 14.5 days).
So for customer 3 is it as follows: 31 days in May, 15 days (0.5*30) in June = 46.
Customer 4 appeared to be two times on the waiting list. 5.5 month in 2018 and 6.5 month in 2019. Between those two periods, the customer wasn't on the waiting list, hence those months should not be included. Therefore, the number of waiting days is 362.5.
I hope this helps.