I need to update a field on one sheet, after an update on another sheet

I've googled many things looking for this and I found many posts here...but none seem to work the way I was expecting.
I'm trying to build a restaurant suggester app for myself... I have a table called Restaurant (R) and a table called Log(L)

L has all the entries as to when I visited each R... and when I add an entry I would like the R Last Visited (LV) to be updated to the most recent entry from L's Date Visited (DV) field.  

R has all the specific details about a location... Name/location/type/cuisine etc.. LV and a times visited (TV).  TV is calculated (COUNT(SELECT((Log[Restaurant]),([Restaurant]=[_THISROW]),true))) but this only happens when the R entry is updated... I don't really want to update the R entry each time manually so I figured if could set the LV value that would trigger the TV value update.

L has a Ref field to R

I can't really seem to locate the best way to do that

I tried creating an action on the R table.. so I could run a bot that returned a value but I could never figure out how to get the value in the Set The Columns formulas

I tried something like this 
LOOKUP(MAX(log[Date Visited]),"log","Date Visited","Date Visited")
but all it does is give me the largest date overall.

I've looked at select(), lookup() and max and maxrow...but I guess I'm not putting this together in the right way.
Thanks for any help
(modified my subject to be a bit less specific and more what people may search for)

0 11 2,035
11 REPLIES 11

As you know the key column's value for the restaurant via the Ref field, you can use the action "Execute an action on a set of rows". It asks you to select rows from the Restaurant table, but you can specify it by LIST([RestaurantID]).. it's the Ref column name in the Logs table.

Then you can read the Timestamp in the action like LOOKUP(MAXROW("Logs","Timestamp",[RestaurantID]=[_THISROW].[KeyColumn]),"Logs","KeyColumn","Timestamp")) or you could do it for example with a virtual column like MAX(SELECT(Logs[Timestamp],[RestaurantID]=[_THISROW].[KeyColumn])). You could use it with the action as well.

The problem with your approach was that you didn't specify the restaurant.

So New Action / Record in Table "Log" / Do this "Data: execute an action on a set of rows" / Referenced Table "Restaurant" / Reference Rows" List([Restaurant])
^This tests and returns the row id... but 

Formatting your suggestion to the table/columns in data sets... looks like this
LOOKUP(MAXROW("Log","Date Visited",[Row ID]=[_THISROW].[Restaurant]),"Log","Restaurant","Date Visited")
Appsheet says (The expression is valid but its result type 'Date' is not one of the expected types: List)


That's if that's all I put in the Referenced Rows... and I supposed to put both the List([Restaurant]) and the Lookup in the referenced rows expression?  like this
LIST([Restaurant])
LOOKUP(MAXROW("Log","Date Visited",[Row ID]=[_THISROW].[Restaurant]),"Log","Restaurant","Date Visited")
if I do this..and hit test I only see the result for the LIST command... since the other one calls out the List vs Date issue.  

So I figured it out... 

Action on Log Table
Name: Trigger Table Update on Restaurant
For record of this table: Log
Do this: Data: Execute an action on a set of rows
Ref Table: Restaurant
Ref Row: Select(Restaurant[Row ID],true) //this causes all rows to update, to prevent invalid data based on deletes or changes...like changing an entry from one restaurant to another.
Action ( new action on Restaurant Table ) named: Run Table Update for Last Visited

Action on Restaurant table:
Name: Run Table Update for Last Visited
For a record of this table: Restaurant
Do this: Data: set the values of some columns in this row
set this column:  Last Visited = 

 

 

LOOKUP(MAX(SELECT(log[Date Visited],([_THISROW].[Row ID] = [Restaurant]))),"log","Date Visited","Date Visited")โ€‹

 

 

and I moved the cell formula for Time Visited here too
so Times Visted: = 

 

 

COUNT(SELECT((Log[Restaurant]),([Restaurant]=[_THISROW])))

 

 

New Bot:

Name: Log Updates
Event Type: Data Change
- Updates Only
Table: Log

New Step: 
Named: Trigger Update Actions
Run a data action
Action to run: Trigger Table Update on Restaurant

Now when I edit an entry in the Log table... it triggers the changes on the Restuarant table! ๐Ÿ™‚
(lol that's a lot... )
Tho I wasn't looking for the LAST row and a specific column... this post helped

this is a link to a specific reply in that post... the layout and explanation here helped... other posts I found on how to trigger actions with the bot got me that far... appreciate the help
Re: FAQ: FILTER(), LOOKUP(), MAXROW(), MINROW(), R... - Google Cloud Community

You could also trigger the action without the Bot if you select the action from the Logs_Form view. The name of the option is "Event actions". It means what action is triggered when the form is saved. Though with the Bot you have more options to control when it's triggered. 

For this you mean... in the Behavior section... set the Event Action for From Saved to my Trigger update on Restaurant?
I tried that and it didn't seem to trigger any updates unless it was a new record that was saving... updating an existing entry didn't trigger this action

^updating... it did work..thank you ๐Ÿ™‚ I was doing the log_form.. and not the slice form lol

But remember that if you modify the old log, it will update the column with the wrong date (not the latest). If the Log table is set as Adds_Only, then it's fine.

So the Log is meant to be edited... it's like a visit log, you enter one each time you go out ... but if you put something in wrong or whatever, you can edit it... so with the update being triggered and using the MAX... the last visited should always be the largest (newest) date so I wouldn't expect that future edit would cause the wrong date to appear. The Date Visited field isn't calculated, it's manually entered... so for example... 

if it had 3 entries for Arby's
7/26/2023
7/24/2023 
7/21/2023 
the restaurant profile should show Last Visited as 7-26
but if I look back and realize I entered 7-21 wrong and go back and update it to the 28th
now the restaurant profile should update to show the last visited as the 7-28

In your case, that's actually true. It works with the Edit as well.

The only issue I now see...are deletes... deleting a log row doesn't trigger the update

Thanks again for the help

With the Bot you have more options and you can do that as well.

With the LIST([Restaurant]) you specify the row in Restaurant table you would need to update. If you want to update the Restaurant record itself, you need to have the LOOKUP(MAXROW(...)) with another action you select with the "Execute an action on a set of rows". That will then update your "Last visited" column in Restaurant table.. and for the correct Restaurant.

Top Labels in this Space