Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
MatCienk
Regular Visitor

Finding common part of Dates dataset

Hello,

I am looking for a solution for showing the collision of dates for the resource usage.

So I have a table with start date column, finish date column and a resource.

I would like to show somehow that the same resource has common set of dates used (in different row of table).

 

I am working on a Driect Query Table which in my opinion makes it harder.

I was tring to list the dates between start and finish and then somehow compare the rows based on single days and resource but can't make that using Direct Query.

 

Example:

Resource A1-1-201030-1-2010 
Resource B1-1-201030-1-2010 
Resource C1-2-201020-2-2010 
Resource A10-1-201015-1-2010Collision!
Resource B1-2-201020-2-2010 
Resource A1-2-201020-2-2010 
1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @MatCienk ,

 

The quickest way I can think to do this within a Direct Query model would be to create a count-over-time measure against your table, using a disconnected calendar table, something like this:

 

_overlapCount = 
VAR __cDate = MAX(calendar[date])
RETURN
CALCULATE(
    COUNT(aTable[resource]),
    KEEPFILTERS(__cDate >= aTable[startDate]),
    KEEPFILTERS(__cDate <= aTable[finishDate])
)

 

 

You can then put aTable[resource], calendar[date], and [_overlapCount] into a table and filter the table on [_overlapCount] > 1, like this:

BA_Pete_0-1669642686555.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

12 REPLIES 12
BA_Pete
Super User
Super User

Hi @MatCienk ,

 

The quickest way I can think to do this within a Direct Query model would be to create a count-over-time measure against your table, using a disconnected calendar table, something like this:

 

_overlapCount = 
VAR __cDate = MAX(calendar[date])
RETURN
CALCULATE(
    COUNT(aTable[resource]),
    KEEPFILTERS(__cDate >= aTable[startDate]),
    KEEPFILTERS(__cDate <= aTable[finishDate])
)

 

 

You can then put aTable[resource], calendar[date], and [_overlapCount] into a table and filter the table on [_overlapCount] > 1, like this:

BA_Pete_0-1669642686555.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




I am not an IT person so sorry if I get something wrong but here is what I've got.

 

I couldn't get it work using disconnected calendar but I have some results useing:

VAR __cDate = MAX(Zadania[Finish])
 
It seems to catch some collision of dates, but not all of them:
1st example:
1.png2.png2nd example:
3.png

 

4.png

 

It catches the collision if the dates are equal, but not if they are contained one within the other.
Would You suggest any fix for that?

Hi @MatCienk ,

 

When you say you couldn't get it to work without a disconnected calendar table, what do you mean? Do you have a calendar table in your model? My answer assumed that you did.

You can add a calendar to your model very easily by going to the Modelling tab> New Table and typing this in the formula bar:

calendar = CALENDARAUTO()

 

It's not the most efficient method of creating a model calendar, but it will get you started.

Once this is done, my original measure should work as expected (Note: you may need to change [date] in my measure to [Date]).

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




I did exactly what You said. After adjusting the code to:

_overlapCount =
VAR __cDate = MAX(Kalendarz[Date])
RETURN
CALCULATE(
    COUNT(Zadania[msdyn_resourceassignment.msdyn_bookableresourceidname]),
    KEEPFILTERS(__cDate >= Zadania[Start]),
    KEEPFILTERS(__cDate <= Zadania[Finish])
)
 
Table just stop showing anything.

 

Is the calendar disconnected in your model view, or has Power BI automatically created a relationship to your fact table without telling you?

 

I've attached a working PBIX file below so you can see how I set it up.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




File really helped .

So what I was doing wrong is not connecting the calendar [date] to the table and that is why it didn't show me any data.

 

Now it works almost perfectly, here are the bugs remaining:

- It didn't catch the colission on date 30.05:

M1.png

 

M1.png

- It detected collision that do not exist ("day 6" - 2023-04-06):

M3.png

 

 

I owe You for solving this case 🙂

 

Are you able to share a more complete example dataset for April and May 2023 please?

These missed/added entries shouldn't be happening so I want to be able to understand what the issue is.

If the source data is very large, then follow these steps to make sharing here easy:

Filter your source table to just these months and this employee then remove all columns except [resource], [startDate], and [endDate], then copy the whole table in Power Query:

BA_Pete_0-1669720069574.png

 

Then go to the Home tab > Enter Data and paste the table into there.

Lastly, open Advanced Editor for your new 'Enter Data' table, copy all of the code in there and paste it into a code window ( </> button ) here.

 

Thanks,

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




let
    Źródło = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZS/CoMwEMZfRZwNXC7+nTt36SoODg4hoAUrhc59tb5XJcYYK02MUDp+8P0ul/suKcsQAZFASjALo7U417dm6B/BiTet6O694GEVzUBGINeAElagIJBoQInvAJMeOgOUEpQndC0XdXAZrvz17EV90D46kCDTdiWs7VA9oUVYAUYY1YASViAmuADxyNgv7G0HtrHb24HUBJyBfQKpG6CZAVDnSMcrgwnYl247I/TNYAJ2Z+Cun5hLkUwr6wDmZ7OI/wO5CThTOAAwMAAK9hR+bcfCsEvh070U/sDu/t318+k3XIlt/eoN", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Finish = _t, Start = _t, Resource = _t]),
    #"Zmieniono typ" = Table.TransformColumnTypes(Źródło,{{"Finish", type date}, {"Start", type date}, {"Resource", type text}})
in
    #"Zmieniono typ"

 

 

I also tried to import this date to Your example file, but I failed, don't know what I am doing wrong (I have replaced the colums in the code properly). 

 

 

I'm not sure I see the issue here.

This is 06/04/2023 - 2 x Mateusz collisions and 4 x Monika collisions:

BA_Pete_0-1669728303648.png

 

This is 30/05/2023 - 3 x Mateusz, 6 x Monika:

BA_Pete_1-1669728421827.png

 

Have I misunderstood the requirements here?

I've attached the updated PBIX below. Updated data on the 'New' tab.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




I think You are 100% correct.

This might be the visualisation issue then.

I have found such note on the calendar I am using:

"f an event lasts for more than a day and the start and end times are before 9 AM, the end date of the event in the visual will be a day before the end date given in the data"

Maybe this is the casue.

Case closed. Big thanks to You!

 

No problem, glad we got it sorted 🙂

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




 

Example data M code for future:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkotzi8tSk5VcFTSUTLUNdQ1MjA0ADKNDWDsWB0kVU5EqXIGqzKCqTIygLFRVIFtNEAYZmiKx0qiDMOqKhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [resource = _t, startDate = _t, finishDate = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"resource", type text}, {"startDate", type date}, {"finishDate", type date}})
in
    chgTypes


Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors