Insert Data into Table B from Table A ONLY if a unique key is not present

Lay of the land:
I have an app for users to log exercise activities for a particular challenge they are enrolled in. The app consists of the following tables:
Challenges
Challenge_Exercises
Challenge_Users
Challenge_Progress
Exercises
Users
User_Stats
Exercise Entry

There are references between some of the tables:
User Stats > Users on User ID
Challenge_Exercises > Exercises on Exercise ID
Challenge_Exercises > Challenges on Challenge ID
Challenge_Users > Users on User ID
Challenge_Users > Challenges on Challenge ID

All of the activities get logged to the Exercise_Entry table which is currently set up with the Challenge ID, User ID, and Exercise ID (among other) fields.

I need to get the Challenge ID, User ID, and Exercise ID copied to the Challenge_Progress table.
The catch, I only want ONE UNIQUE record in the table for a given Challenge ID, User ID, Exercise ID.

The challenge_user table is designed to store total complete reps by a given Challenge ID, User ID, and Exercise ID. This will drive some charting and other information displayed on the dashboard.

I am struggling to figure out how to perform the lookup with all of those IDs against that table to determine if that โ€œkeyโ€ exists. FYI I do have a column on that table to store that โ€œkeyโ€

let me know if you need more information or detail

Solved Solved
0 12 1,724
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

The following expression can be used from the Exercise_Entry table to determine if the (User ID, Challenge ID, Execise ID) combo of a given row of that table already exists in a row of the Challenge_Progress table:

ISBLANK(
  FILTER(
    "Challenge_Progress",
    AND(
      ([_THISROW].[User ID] = [User ID]),
      ([_THISROW].[Challenge ID] = [Challenge ID]),
      ([_THISROW].[Exercise ID] = [Exercise ID])
    )
  )
  - LIST([_THISROW])
)

View solution in original post

12 REPLIES 12

Steve
Platinum 4
Platinum 4

The following expression can be used from the Exercise_Entry table to determine if the (User ID, Challenge ID, Execise ID) combo of a given row of that table already exists in a row of the Challenge_Progress table:

ISBLANK(
  FILTER(
    "Challenge_Progress",
    AND(
      ([_THISROW].[User ID] = [User ID]),
      ([_THISROW].[Challenge ID] = [Challenge ID]),
      ([_THISROW].[Exercise ID] = [Exercise ID])
    )
  )
  - LIST([_THISROW])
)

Hello to everyone

in this same way I want to trigger action of add new row in another table Via workflow.

data from attendance and target table is salary

condition is it will only trigger if employee month and year data are not available in salary table,

so by this ways it will trigger only once in month.

i tried this

ISBLANK(
FILTER(
โ€œsalaryโ€,
AND(
([_THISROW].[MONTH] = [MONTH]),
([_THISROW].[F.YEAR] = [F.YEAR]),
([_THISROW].[OPERATOR] = [OPERATOR NAME])
)
))

success

UPDATING MY STATUS

its work perfectly

i have a problem in the month column I change it from date to text type same as the attendance table.

solve, one more time thax sir

Thanks @Steve. I was actually just looking at that example on another thread you were working on. And already trying to work that example in.

Now I need to figure out the action/workflow to get the data to insert into that table when there is an entry made into the Exercise_Entry table (with the validation).

Iโ€™d think youโ€™d want an action of type Data: add a new row to another table using values from this row with the expression I provided above as the actionโ€™s Only if this condition is true expression. Then attach that action as the Form saved event action for the Exercise_Entry tableโ€™s form view.

Thanks! I started to fiddling through setting up the actions/workflow. Iโ€™ll report back in a bit if I have any hiccups.

Thanks again for the help!

@Steve Thanks for the help with the validation, it works great. I got everything logging to that table except for one piece. I thought I had it figured out, but for some reason it just wonโ€™t work.

In addition to the User ID, Challenge ID, Exercise ID, and Date (that one was new) I need to insert a value from a different table. The value is coming from the Challenge_Exercise table where the Challenge ID and Exercise ID exist. I need to pull the Target_Reps value and insert it along with the previous 4 values during the action trigger. Hereโ€™s what I thought would do itโ€ฆ(added to the action trigger from above) Trying to set the โ€˜Targetโ€™ field on the Challenge_Progress table =

Any(
   select(challenge_exercises[Target Reps],
      AND(
                ([Challenge ID]=[Challenge ID]),
                ([Exercise ID]=Exercise ID]),
                (today()>=[Start Date]),
                (today()<=[End Date])
                )               
                )
         )

Any suggestions

At the very least, your expression is missing the [_THISROW] dereferences mine had. Those are critical.

See also:

Thanks for the tips and pointing me in the general direction for learning. I was able to troubleshoot and get what I needed to work. Still learning all the ins and outs of AppSheet.

Question, do you know if there is a way to update a field on a given table that is triggered by changes to a different table? Based on my trials and errors, the action to set the value of a column canโ€™t be triggered by events on a different table (you can only add rows - and I donโ€™t want to delete and re-add rows).

Objective: I am trying to update the Completed column for the row we inserted above in the Challenge_Progress table with the sum of reps for a given exercise

The validations and math to get the values and update the appropriate records is done. I just cannot figure out to trigger the actionโ€ฆ I know Iโ€™m missing something.

Updateโ€ฆ it appears that I got it working.

Action 1:
For a record of this table: Select the main table
Do this: Select โ€˜Data: Set values of some columns in this rowโ€™
Select the columns: Define the columns you want to update and the value to update them with

Action 2:
For a record of this table: Select the secondary table
Do this: Select โ€˜Data: execute an action on a set of rowsโ€™
Referenced table selection: Select the main table
Refโ€™d Rows: Define the value from a column of the secondary table that picks correct row in main table.
Refโ€™d action: Select the name of you gave for โ€˜Action 1โ€™

Workflow
When this happens:

  • Target Data: Select the secondary table
  • Update Event: Select the action that triggers the workflow

Do this:
Reaction: Select โ€˜Change Dataโ€™
Workflow Action Name: Enter a name
Data Change Action Name: Select โ€˜Action 2โ€™

Seems to be working perfectly

OUTSTANDING!!! Very well done!

Please share the demo

Top Labels in this Space