Forum Discussion
Anonymous
6 years agoNot applicable
Average date difference between two dates in same column
Hi everyone, I want to calculate the average waiting time for our customers. The table shows a small sample set (see below). We only have data once a month. To be precise as possible, I want to...
- 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
Greg_Deckler
6 years agoCommunity Champion
You might be able to use a variation of Cthulhu to get your group id column. https://community.powerbi.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739#M211