Correctly Update Parent data with Child Record/Related Data

Hi,

I have 3 Tables. Customer, Appointments, Photos.
Customers have Appointments.
Both Customers and Appointments can have Photos.

I was struggling to update a Customer record with itโ€™s latest Appointment data. Namely the Date, Time, Time Slot, and Charge for the Appointment.

I found topic 14257 and used this as a solution. The Customer table has a related Appointments Column. I can use trigger an ADD_and_UDPATES Action on Appointments_Form which triggers an Action on the Customer table for the Customer row to update its data from its most recent appointmentโ€ฆ

The Date - MAX([Related Appointments][Date])

And the Time, Time Slot, Charge with the expression

LOOKUP(
 MAX(
  SELECT(
    [Related Appointments][_ROWNUMBER],
    ([Date] = MAX([Related Appointments][Date]))
    )
  ),
  โ€œAppointmentsโ€,
  โ€œ_ROWNUMBERโ€,
  โ€œTimeโ€
)

Now this works, and iโ€™m very happy with the result but it feels a little wrong doing 3 lookups on the Appointments table when all the data I need is already in the Related Appointments column in the Customer Table.

Is there a cleaner way of doing this?

Many thank

Tris

0 2 548
2 REPLIES 2

Another option may be something like this:

ANY(SORT(SELECT(Appointments[Time], [Customer]=[_THISROW].[Customer]), TRUE))

You mean this right?

Yes and no.

Since it sounds like youโ€™re using real columns (not Virtual), and triggering the recalculation only when it is needed, I wouldnโ€™t really worry about using lots of LOOKUP()s/SELECT()s, as it wonโ€™t hamper performance too much. Nevertheless, here is another option for you to consider.

Add an additional column to your Table, of Ref type, pointing to the child Table. From your Bot, update this columnโ€™s value with:

ANY( SELECT(
    [Related Appointments][#key-column-here#],
    [Date] = MAX([Related Appointments][Date])
)   )

Then you can use this column to do simple โ€œdereferencesโ€ for all of the other values from that record.

[new-column].[Time]
[new-column].[Charge]

etcโ€ฆ

Top Labels in this Space