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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
Solution Sage
Solution Sage

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.