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
sreedhary
Frequent Visitor

How to check the date value of one table date column is in between the 2 row values of another table

Hi, I am struggling with the following issue in Power BI desktop. My requirement is, how to check the Date Time value in Table A is in between the Sighting Date time values in Table B, if it is in between then show the minimum date/time record from Table B along with Table A record. In the below example, the record value 3/5/2020 3:48:33 PM from Table A is in between the date time values which are in 2 rows (3/4/2020 4:33:00 PM and 3/6/2020 5:33:00 AM) in Table B. In this show the minimum date-time record from Table B along with Table A row. I am in need of your helpo how to achieve this in Power BI desktop. The expected results is shown below.
Thank you for your help.

Table A:

Car NumberDate TimeEvent Type
ACTX0232933/5/2020 3:48:33 PMShock

 

Table B:

Car NumberSighting Date TimeIndicator
ACTX0232933/4/2020 4:33:00 PML
ACTX0232933/6/2020 5:34:00 AML
ACTX0232933/6/2020 7:44:15 AML

 

Expected Result:

Car NumberDate TimeEvent TypeSighting Date TimeIndicator
ACTX0232933/5/2020 3:48:33 PMShock3/4/202 4:33:00 PML
8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

These calculated column formulas work in Table1

Sighting Date Time = CALCULATE(Max(Table2[Sighting Date Time]),FILTER(Table2,Table2[Car Number]=EARLIER(Table1[Car Number])&&Table2[Sighting Date Time]<=EARLIER(Table1[Date Time])))
=LOOKUPVALUE(Table2[Indicator],Table2[Car Number],Table1[Car Number],Table2[Sighting Date Time],Table1[Sighting Date Time])

Hope this helps.

Untitled.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ashish, Thank you for the calculations. I implemented these and testing the report  now. I will let keep you posted the updates.

 

Again, appreciate for your help.

Ashish,  The solution you propsed worked. Thank you so much for your help.

 

Thanks,

Sreedhar

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
V-pazhen-msft
Community Support
Community Support

@sreedhary 

Try create the following two columns in Table A.

 

Sighting Date Time 1 = CALCULATE(MAX('Table B'[Sighting Date Time]),FILTER('Table B',[Sighting Date Time]<'Table A'[DateTime]&&'Table B'[Car Number]='Table A'[Car Number]))

Indication 1 = CALCULATE(MAX('Table B'[Indication]),FILTER('Table B',[Sighting Date Time]<'Table A'[DateTime] &&'Table B'[Car Number]='Table A'[Car Number]))

 

 

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

Paul, Thank you for the formulas. I implemented these and testing the report. I will let you know if there are any issues.

 

Again, appreciate for your help.

amitchandak
Super User
Super User

@sreedhary , New column in Table 1

New column = minx(filter(Table2,Table1[Car Number] =Table2[Car Number] && Table1[Date Time] >Table2[Date Time] ),Tabl22[Date Time])

Amit, Thank you for the response. But I am getting error when I use the suggested expression.

"Query(5,5) A single  value for a column 'Car Number' in table Table A can not be detemined..."

 

Moreover, I need to check the Table A date column value is in between the Table B Date column values (note: these spanned 2 rows).

Hope I am clear. Please let me know.

 

Pleasae advise.

 

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.