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:
Hi SebastianAlmer
Add a index column to your table and then Create two calculated column like this:
Time Flag =
var previousendhour=CALCULATE(MAX('Table'[end_hour]),FILTER(ALLEXCEPT('Table','Table'[date]),'Table'[Index]=EARLIER('Table'[Index])-1))
var previousendminute=CALCULATE(MAX('Table'[end_minute]),FILTER(ALLEXCEPT('Table','Table'[date]),'Table'[Index]=EARLIER('Table'[Index])-1))
var previousendtime= (previousendhour*100)+previousendminute
var starttime=('Table'[start_hour]*100)+'Table'[start_minute]
var timeflag=IF(starttime<previousendtime,1,0)
return timeflag
Next Time Flag = CALCULATE(MAX('Table'[Time Flag]),FILTER(ALLEXCEPT('Table','Table'[date]),'Table'[Index]=EARLIER('Table'[Index])+1))Time Filter = IF(SUM('Table'[Time Flag])=1 || sum('Table'[Next Time Flag])=1,1,0)
Please accept this as a solution if your question has been answered !!
Appreciate a Kudos 😀