Forum Discussion
Hour Duration between two different rows from different columns in Power BI
Hi sushmitasur4 ,
You can follow the steps below to get it:
1. Add index column in Power Query Editor
= Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)
2. Create a calculated column as below
Column =
VAR _count =
CALCULATE (
COUNT ( 'Table'[Index] ),
FILTER (
ALL ( 'Table' ),
'Table'[Type] = EARLIER ( 'Table'[Type] )
&& 'Table'[Index]
= EARLIER ( 'Table'[Index] ) - 1
)
)
VAR _prestart =
CALCULATE (
MAX ( 'Table'[Start] ),
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
)
RETURN
IF ( ISBLANK ( _count ), BLANK (), DATEDIFF ( _prestart, 'Table'[End], HOUR ) )
Best Regards
- sushmitasur42 years agoRegular Visitor
The table below is the reference. The Hour Duration is the expected Output actually.
- Anonymous2 years agoNot applicable
Hi sushmitasur4 ,
Why the Hours Duration is "01:06:00" when Index is 5? Could you please provide the related calculation logic?
Best Regards
- sushmitasur42 years agoRegular Visitor
Here's the Pseudo Code of the logic calculation I need:
BypassedHoursColumn =
When typecolumn = 3: Variable MinTime = Start_TimeStamp
When typecolumn !=3:
IF PreviousRow((End_TimeStamp)) == Non-Blank:
Variable MaxTime = PreviousRow((End_TimeStamp)) and Store (MaxTime - MinTime)
IF PreviousRow((End_TimeStamp)) == Blank:
Variable MaxTime = PreviousRow((End_TimeStamp)) and Store (NOW() - MinTime)