Forum Discussion
Get Datediff by group
- 6 years ago
Hi, AlexGlz
If I didn't misunderstand your meaning ,you can try the following steps:
- Sort the table by “id” and “ date”
- Insert a index column into the table to help you create DAX.( You can right-click to hide the created index column if you don't need to display it )
- Create calculate columns “Next Date01” and “Datediff” like that :
Next Date01 = var ind='Date'[Index]+1 var nextdate=CALCULATE(MAX('Date'[Date]),FILTER('Date','Date'[Index]=ind)) var nextid=CALCULATE(MAX('Date'[id]),FILTER('Date','Date'[Index]=ind)) var val=IF('Date'[id]=nextid,nextdate,TODAY()) return val DateDiff = var days=DATEDIFF('Date'[Date],'Date'[Next Date01],DAY) RETURN days Here’s a sample I made:
Best Regards,
Eason
Community Support Team _ Eason Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, AlexGlz
If I didn't misunderstand your meaning ,you can try the following steps:
- Sort the table by “id” and “ date”
- Insert a index column into the table to help you create DAX.( You can right-click to hide the created index column if you don't need to display it )
- Create calculate columns “Next Date01” and “Datediff” like that :
Next Date01 =
var ind='Date'[Index]+1
var nextdate=CALCULATE(MAX('Date'[Date]),FILTER('Date','Date'[Index]=ind))
var nextid=CALCULATE(MAX('Date'[id]),FILTER('Date','Date'[Index]=ind))
var val=IF('Date'[id]=nextid,nextdate,TODAY())
return
val
DateDiff =
var days=DATEDIFF('Date'[Date],'Date'[Next Date01],DAY)
RETURN days
Here’s a sample I made:
Best Regards,
Eason
Community Support Team _ Eason Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Unfortunately for now I couldn't make the index column because I'm taking the Data from a sharepoint and I don't know if the server has issues or something but I Power BI can't autenticate my credentials, so I can't add any column in power Query...
I will try again in the next days...