Remember a user preference

I have a form that records (1) a user's email, (2) a choice between some treats (let's say "cake", "cupcakes", or "cookies") and (3) several other fields. How can I set up my form so that the first time a user goes through it the form records which treat they like, and the next time they complete the form it remembers which treat they said they liked last time (but they can still change it this time if they want to, and it will be remembered next time)?

I have tried creating a user table that records their treat preferences, have used a lookup expression in the form's table to find what treat they like (to pre-populate the field), but am stuck trying to figure out how to construct the actions so that their treat preferences get updated if they make a change on the form. It would really help me if someone could explain how to go about this structurally. I need the form to add rows to the user column if they don't exist, or update the row if the user changes their preference. Thanks in advance for any thoughts.

Solved Solved
0 6 305
1 ACCEPTED SOLUTION

Apologies, the ORDERBY has to return a list of row keys so you could adjusted your SELECT to pull the row key and then include that result in another select. Alternatively you could leverage your MAXROW version with something like: ANY(SELECT(Treats[Treat],[Unique ID]=MAXROW("Treats", "Timestamp",[User email]=[_THISROW].[User email])))

View solution in original post

6 REPLIES 6

You could skip the user table altogether and simply have the form on the treats table set up so that the initial value for each field is the last value the user entered. 
Add a timestamp field and then a SELECT() and ORDERBY() to get the last record from that user.

Thanks for that tip; it sounds very promising. However, I can't get it to work. Here's what I've tried:

ORDERBY(SELECT(Treats[Treat],[User email]=[_THISROW].[User email],TRUE), Timestamp)

But that tells me "ORDERBY has invalid inputs". Have read and re-read the docs, but I must be thick-skulled. So I also tried:

MAXROW("Treats", "Timestamp",[User email]=[_THISROW].[User email])

Which doesn't break anything, but it also doesn't "preselect" the last treat that user chose. Again, probably because I'm dense. For reference, my table is set up like this:

pete3_0-1699982892743.png

Any other pointers?

 

Try 
INDEX(ORDERBY(SELECT(Treats[Treat],[User email]=[_THISROW].[User email],TRUE), [Timestamp],TRUE),1)

The validator still gives me "ORDERBY has invalid inputs" when I put that in. There must be something I'm doing wrong in the ORDERBY, but I can't figure out what.

Apologies, the ORDERBY has to return a list of row keys so you could adjusted your SELECT to pull the row key and then include that result in another select. Alternatively you could leverage your MAXROW version with something like: ANY(SELECT(Treats[Treat],[Unique ID]=MAXROW("Treats", "Timestamp",[User email]=[_THISROW].[User email])))

Fantastic; the function using ANY and MAXROW works! Thanks for your help!

Top Labels in this Space