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:
I've switched to import for testing:
jaideepnema
I have an index that I can use. But it's not ordered by anything. Your index needs to be ordered I assume? Like in the solution of PaulDBrown
PaulDBrown I've tested your solution. It seems, that it only works, if there are two entries per day, right? How could I do this not knowing how many entries per day?
really appreciate your help🙏
- PaulDBrown5 years agoCommunity Champion
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:
- Anonymous3 years agoNot applicable
Can you share the .pbix file of this solution on the forum? Thanks.
- jaideepnema5 years agoSolution Sage
Hi SebastianAlmer ,
Yes the index needs to be in a sorted order ...preferably in ascending order.....