Forum Discussion
calculation between non consecutives rows
- Anonymous2 years ago
Thanks for the reply fromlbendlin ,please allow me to provide another insight:
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2.Create calculated column references:
predate = VAR currentdate = 'kk'[date] RETURN IF ( 'kk'[gap] = "gap", MAXX ( FILTER ( 'kk', 'kk'[gap] = "gap" && 'kk'[date] < currentdate && 'kk'[id] = EARLIER ( kk[id] ) ), 'kk'[date] ), BLANK () )diffhour = DATEDIFF('kk'[predate],'kk'[date].[Date],HOUR)diffmonth = DATEDIFF('kk'[predate],'kk'[date].[Date],MONTH)3.Here's my final result, which I hope meets your requirements.
4.Here is the relevant documentation:
DATEDIFF function (DAX) - DAX | Microsoft Learn
Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the reply fromlbendlin ,please allow me to provide another insight:
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2.Create calculated column references:
predate =
VAR currentdate = 'kk'[date]
RETURN
IF (
'kk'[gap] = "gap",
MAXX (
FILTER (
'kk',
'kk'[gap] = "gap"
&& 'kk'[date] < currentdate
&& 'kk'[id] = EARLIER ( kk[id] )
),
'kk'[date]
),
BLANK ()
)diffhour = DATEDIFF('kk'[predate],'kk'[date].[Date],HOUR)diffmonth = DATEDIFF('kk'[predate],'kk'[date].[Date],MONTH)
3.Here's my final result, which I hope meets your requirements.
4.Here is the relevant documentation:
DATEDIFF function (DAX) - DAX | Microsoft Learn
Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.