Forum Discussion
identify overlapping entries
- 5 years ago
If you wish to use Direct Query, you can (NB, I've added another overlapping row to date 2/03/2021 to check if all overlapping rows are returned) :
1) Create the DateTime columns in the table using calculated columns with:
StartTime = TableDQ[date] & " " & TableDQ[start_hour] & ":" & TableDQ[start_minute]And the equivalent for the EndTime column. Set the Data type to Date/time:
2) Create a measure to establish the row order by date/employee/task:
Sum StartTime = SUM(TableDQ[StartTime])Order by date = RANKX ( FILTER ( ALLEXCEPT ( TableDQ, TableDQ[employee], TableDQ[date], TableDQ[Task] ), NOT ( ISBLANK ( [Sum StartTime] ) ) ), [Sum StartTime], , ASC )This gives you the following table visual:
3) Next create measures to establish the StartDateTime and EndDateTime for the comparison:
StartDateTime = VAR starttime = MAX ( TableDQ[StartTime] ) RETURN CALCULATE ( starttime, ALLEXCEPT ( 'TableDQ', 'TableDQ'[date], 'TableDQ'[employee], 'TableDQ'[Task] ) )EndDateTime = VAR PrevPeriod = [Order by date] - 1 RETURN CALCULATE ( MAX ( TableDQ[EndTime] ), FILTER ( ALLEXCEPT ( TableDQ, 'TableDQ'[date], 'TableDQ'[employee], TableDQ[Task] ), [Order by date] = PrevPeriod ) )4) and finally the measure to identify the rows which overlap:
Indentify overlapping DQ = VAR SelPeriod = CALCULATE ( [Order by date], FILTER ( TableDQ, NOT ( ISBLANK ( [EndDateTime] ) ) ) ) VAR _table = CALCULATETABLE ( VALUES ( TableDQ[date] ), FILTER ( TableDQ, [Order by date] >= SelPeriod - 1 && [Order by date] <= SelPeriod ) ) VAR _date = CALCULATETABLE ( VALUES ( 'TableDQ'[date] ), FILTER ( ALL ( TableDQ ), [StartDateTime] < [EndDateTime] ) ) RETURN COUNTROWS ( INTERSECT ( _table, _date ) )And you will get this:
SebastianAlmer
I'm not too sure if this will work flawlessly but...
1) Create a new columns in Power Query to return the Date StartTime and Date EndTimes per row.
2) Add a new calculated column to rank the rows by employee, date and task in ascending order based on the StartTime value:
3) Create a measure to check if a start time overlaps an end time:
Indentify overlapping =
VAR EndDateTime =
CALCULATE (
MAX ( 'Table'[End DateTime] ),
FILTER (
ALLEXCEPT ( 'Table', 'Table'[date], 'Table'[employee], 'Table'[Task] ),
'Table'[Order] = 1
)
)
VAR StartDateTime =
CALCULATE (
MAX ( 'Table'[Start DateTime] ),
FILTER (
ALLEXCEPT ( 'Table', 'Table'[date], 'Table'[employee], 'Table'[Task] ),
'Table'[Order] = 2
)
)
RETURN
IF ( StartDateTime < EndDateTime, 1 )
And you get this: