Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
3 years ago
Solved

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.

  • Ashish_Mathur's avatar
    Ashish_Mathur
    3 years ago

    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.

5 Replies

  • 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

  • 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?

  • 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!

    • Ashish_Mathur's avatar
      Ashish_Mathur
      Super User

      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.

  • 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.