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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jadewind
Helper I
Helper I

Matching dates

I have two tables, one showing people's IDs, Locations and Start Date and End Date of people's locations , the other one showing incidents with Incident Date and people's IDs. 

 

I want to find out where the people were when the incidents happened. So it's about matching the Incident Date with the Start/End Date to get the Location.

 

How can I achieve this in Power BI?

1 ACCEPTED SOLUTION

Hi  @jadewind

I haven't created ant relationship between the two tables. You can check the attached PBIX file to get more details about how to create the calculated column.

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

Hi @jadewind,

Do you want to get the location when Incident Date equals to the Start Date or End Date? If that is the case, I make a test using the following two tables.
1.PNG

2.PNG

In Table5, you can just create a calculated column using the formula below, then create a table visual using the calculated column and other fields.

GetLocation = CALCULATE(FIRSTNONBLANK(Table4[Locations],Table4[Locations]),FILTER(Table4,(Table4[Start Date]=Table5[Incident Date]||Table4[End Date]=Table5[Incident Date])&&Table4[ID]=Table5[ID]))

3.PNG

However, if you want to get the location when Incident Date is between Start Dare and End Date, just create a calculated column using the formula below, then create a table visual using the calculated column and other fields.

GetLocation1 = CALCULATE(FIRSTNONBLANK(Table4[Locations],Table4[Locations]),FILTER(Table4,Table4[Start Date]<=Table5[Incident Date]&&Table5[Incident Date]<=Table4[End Date]&&Table4[ID]=Table5[ID]))
4.PNG

 

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Or I think the bit after <= has to be a measure not a column?

Hi  @jadewind

I haven't created ant relationship between the two tables. You can check the attached PBIX file to get more details about how to create the calculated column.

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Lydia for trying to help. However your formula does not work when I started the second row. I think it has something to do with the relationship between two tables. I cannot link the two tables directly because the ID fields in both tables have duplicates - meaning each ID can have multiple locations through different dates, and each ID can have multiple incidents. However each incident has a unique Incident No. 

 

Not sure how I can upload a sample xlsx document but I have attached a couple of snapshots below. One table contains the incident dates, the other table contains the locations data. I have tried linking the two tables using another Date or ID table but still couldn't use your formula (eg. the formula wouldn't recoganize the "Incident Date" field). 

 

Do you have any suggestions?

incidents.JPG

locations.JPG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.