Forum Discussion
I need to get data from previous row based on multiple columns
- Anonymous3 years ago
Hi Anonymous ,
Create a calculated column called Previous Action Date that returns the Action Date of the previous row for each Brief Id. You can use the EARLIER function to refer to an earlier row context. For example:
Previous Action Date = CALCULATE ( MAX ( 'Table'[Action Date] ), FILTER ( 'Table', 'Table'[Brief Id] = EARLIER ( 'Table'[Brief Id] ) && 'Table'[Seq. No.] = EARLIER ( 'Table'[Seq. No.] ) - 1 ) )Create another calculated column called Time Taken that returns the difference in seconds between the Action Date and the Previous Action Date for each row. You can use the DATEDIFF function to calculate the difference. For example:
Time Taken = DATEDIFF ( 'Table'[Previous Action Date], 'Table'[Action Date], SECOND )To exclude weekends (Saturday and Sunday) from the time taken calculation, you can use the WEEKDAY function to check the day of the week for each date and subtract the number of weekend days from the difference. For example:
Time Taken (Excluding Weekends) = VAR Diff = DATEDIFF ( 'Table'[Previous Action Date], 'Table'[Action Date], DAY ) VAR StartDay = WEEKDAY ( 'Table'[Previous Action Date], 2 ) VAR EndDay = WEEKDAY ( 'Table'[Action Date], 2 ) VAR WeekendDays = INT ( Diff / 7 ) * 2 + IF ( MOD ( Diff, 7 ) + StartDay > 6, 2, 0 ) + IF ( AND ( MOD ( Diff, 7 ) + StartDay > 5, EndDay < StartDay ), -1, 0 ) RETURN DATEDIFF ( 'Table'[Previous Action Date], 'Table'[Action Date], SECOND ) - WeekendDays * 24 * 60 * 60How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ RongtieIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Create a calculated column called Previous Action Date that returns the Action Date of the previous row for each Brief Id. You can use the EARLIER function to refer to an earlier row context. For example:
Previous Action Date =
CALCULATE (
MAX ( 'Table'[Action Date] ),
FILTER (
'Table',
'Table'[Brief Id] = EARLIER ( 'Table'[Brief Id] )
&& 'Table'[Seq. No.]
= EARLIER ( 'Table'[Seq. No.] ) - 1
)
)
Create another calculated column called Time Taken that returns the difference in seconds between the Action Date and the Previous Action Date for each row. You can use the DATEDIFF function to calculate the difference. For example:
Time Taken =
DATEDIFF ( 'Table'[Previous Action Date], 'Table'[Action Date], SECOND )
To exclude weekends (Saturday and Sunday) from the time taken calculation, you can use the WEEKDAY function to check the day of the week for each date and subtract the number of weekend days from the difference. For example:
Time Taken (Excluding Weekends) =
VAR Diff =
DATEDIFF ( 'Table'[Previous Action Date], 'Table'[Action Date], DAY )
VAR StartDay =
WEEKDAY ( 'Table'[Previous Action Date], 2 )
VAR EndDay =
WEEKDAY ( 'Table'[Action Date], 2 )
VAR WeekendDays =
INT ( Diff / 7 ) * 2
+ IF ( MOD ( Diff, 7 ) + StartDay > 6, 2, 0 )
+ IF ( AND ( MOD ( Diff, 7 ) + StartDay > 5, EndDay < StartDay ), -1, 0 )
RETURN
DATEDIFF ( 'Table'[Previous Action Date], 'Table'[Action Date], SECOND ) - WeekendDays * 24 * 60 * 60
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ Rongtie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.