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
Syndicate_Admin
Administrator
Administrator

Check dates between two tables with multiple validations

Good afternoon, I have two tables related by a multi-to-many related ID and I need to do date checks between different tables. Example:

Table 1:

IDStart dateEnd date
101/04/202310/04/2023
115/04/202320/04/2023
201/04/202320/04/2023
302/04/202305/04/2023

Table 2:

IDProgramming dateType of visitDate of visit
110/04/2023A30/04/2023
110/04/2023B27/04/2023
120/04/2023B30/04/2023
219/04/2023A25/04/2023
306/04/2023B18/04/2023
308/04/2023A25/04/2023

What I need is:

  • Calculate whether programming date (table 2) is ≥ to start date (table 1) and ≤ end date (table 1)
  • Identify which is the first to meet the precondition and what type of visit it is (table 2)
  • Calculate the difference between the end date (table 1) and the first visit date (table 2)

The result would be something like this:

IDStart date (table 1)End date (table 1)Scheduled (Start Date ≤ Schedule Date ≤ End Date)Date of visitType visitTime to visit
101/04/202310/04/2023Yes27/04/2023B17
115/04/202320/04/2023Yes30/04/2023B10
201/04/202320/04/2023Yes25/04/2023A5
302/04/202305/04/2023No

I've tried multiple ways, but I'm not able to do it.

Thanks in advance.

1 ACCEPTED SOLUTION

Hi,

You can get the yes and no with this calculated column formula in Table1

Column = if(CALCULATE(COUNTROWS(Table2),FILTER(Table2,Table2[Programming date]>=EARLIER(Table1[Start date])&&Table2[Programming date]<=EARLIER(Table1[End date])&&Table2[ID]=EARLIER(Table1[ID])))>0,"Yes","No")

Hope this helps.

Untitled.png


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

View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Good morning

  • The answer is 27/04 and A because it is the one that has the least difference in dates with respect to the end date 20/04 and B. If it were B and 30, the time to visit would be 20.
  • Filtering from several to many and the address is between both from table 1 to table 2 and from table 2 to table 1.
  • I would need to see both "Yes" and "No" values, although "Yes" would suffice.
Syndicate_Admin
Administrator
Administrator

Good morning

The answer is 27/04 and A because it is the one that has the least difference in dates with respect to the end date 20/04 and B. If it were B and 30, the time to visit would be 20.

Thank you!

Hi,

You can get the yes and no with this calculated column formula in Table1

Column = if(CALCULATE(COUNTROWS(Table2),FILTER(Table2,Table2[Programming date]>=EARLIER(Table1[Start date])&&Table2[Programming date]<=EARLIER(Table1[End date])&&Table2[ID]=EARLIER(Table1[ID])))>0,"Yes","No")

Hope this helps.

Untitled.png


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

Hi,

I cannot understand the date of viit column in the third table.  For ID1, why should the answer be 27/4 for the first instance?  Why is it not 30/4?


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

Hi @Syndicate_Admin ,

I do not understand your output. Isn't it wrong?

 

1-Why visit type A for ID 1 is not in the output?

 

2-How is your relationship crossfiltering behavior? Both? From Table 1 to Table 2 or table 2 to table 1?

 

3- You want to see only the "YES" values? Please provide exact output based on your sample data.

 

Regards,

Loran

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.