# Creating records in a related table

**URL:** <https://community.glideapps.com/t/creating-records-in-a-related-table/36880>\
**Category:** Ask for Help\
**Created:** [January 9, 2022, 7:46am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880 "2022-01-09T07:46:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krisztian\_Gyuris](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krisztian_gyuris/32/36302_2.png) [@Krisztian\_Gyuris](https://community.glideapps.com/u/Krisztian_Gyuris)\
**Post date:** [January 9, 2022, 7:46am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/1 "2022-01-09T07:46:39Z")

</div>

I am working on a simple stock tracker app where the user can enter their trades and it would show the summary of their position. When the user enters the first transaction of a given stock (Apple) then I need to create a row in a positions table for that stock (Apple) where I am going to summarize all of the trades. Is there a way to do this in glide or I need to use something like Zapier?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 9, 2022, 8:06am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/2 "2022-01-09T08:06:57Z")

</div>

If you want to create a related record then I can advise using a custom form, but I want to know more about your data structure here.

Do you have a Users table, a Stocks table, a Trades table and a Positions table? How are the Trades and Positions table related?

---

<div class="post-metadata">

**Author:** ![Krisztian\_Gyuris](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krisztian_gyuris/32/36302_2.png) [@Krisztian\_Gyuris](https://community.glideapps.com/u/Krisztian_Gyuris)\
**Post date:** [January 10, 2022, 9:46am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/3 "2022-01-10T09:46:31Z")

</div>

@ThinhDinh thanks for the reply.

I have one or more APPL trades in the transactions table:  
stock\_symbol, type, count, transaction\_price, transaction\_date, total\_cost, current\_value  
APPL, BUY, 10, $60, 2022-01-07, $600, $700  
AAPL, BUY 20, $65, 2022-01-08. $1300, $1400

Then in the positions table the AAPL line would be auto-created when the first AAPL transaction entered and it would be basically sum up your AAPL trades:

stock\_symbol, total\_count, total\_cost, current\_value  
AAPL, 30, $1900, $2100

I am not sure if this needs an extra table or somehow I can create it from the transactions table though. I am open to all suggestions

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 10, 2022, 12:00pm UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/4 "2022-01-10T12:00:49Z")

</div>

> [@Krisztian\_Gyuris](#):
>
> I have one or more APPL trades in the transactions table:  
> stock\_symbol, type, count, transaction\_price, transaction\_date, total\_cost, current\_value  
> APPL, BUY, 10, $60, 2022-01-07, $600, $700  
> AAPL, BUY 20, $65, 2022-01-08. $1300, $1400

Looks like you need to record the user’s email/ID here as well, if you’re having multiple users using the app.

Let’s say it will look like this:

email, stock\_symbol, type, count, transaction\_price, transaction\_date, total\_cost, current\_value  
[thinh@example.com](mailto:thinh@example.com), APPL, BUY, 10, $60, 2022-01-07, $600, $700  
[thinh@example.com](mailto:thinh@example.com), AAPL, BUY, 20, $65, 2022-01-08. $1300, $1400

Then you create a template column in the same sheet joining the email and the stock\_symbol. It should look like:

[thinh@example.com](mailto:thinh@example.com) - APPL.

Then create a multiple relation using that template column to itself, so you get all the transactions from the same email and the same stock.

Finally, you can use 3 sum rollups to calculate the total count, cost and current value.

---

<div class="post-metadata">

**Author:** ![Krisztian\_Gyuris](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krisztian_gyuris/32/36302_2.png) [@Krisztian\_Gyuris](https://community.glideapps.com/u/Krisztian_Gyuris)\
**Post date:** [January 11, 2022, 6:10am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/5 "2022-01-11T06:10:47Z")

</div>

Thanks for the reply. So it seems like I will not need the Positions table at all because the template string with the thinh@example.com-APPL and the relation will be able to compute the total cost, total count and current value.

I have one last question though. How do I display this data to the user so each stock position is shown only once?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 12, 2022, 12:09am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/6 "2022-01-12T00:09:31Z")

</div>

I assume you have a rowID for each transaction.

Then, from the relation I mentioned here.

> [@ThinhDinh](#):
>
> Then create a multiple relation using that template column to itself, so you get all the transactions from the same email and the same stock.

You add a single value \> return first rowID from the relation, you will have the rowID of the first transaction that matches.

Then filter if rowID is first rowID from the single value column above.

---

<div class="post-metadata">

**Author:** ![Krisztian\_Gyuris](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/krisztian_gyuris/32/36302_2.png) [@Krisztian\_Gyuris](https://community.glideapps.com/u/Krisztian_Gyuris)\
**Post date:** [January 17, 2022, 9:07am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/7 "2022-01-17T09:07:03Z")

</div>

This is gold! 🙂 Thank you for your help.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 17, 2022, 9:13am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/8 "2022-01-17T09:13:57Z")

</div>

That is one clean way to have a “unique” list without creating another table 😉

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [January 18, 2022, 9:14am UTC](https://community.glideapps.com/t/creating-records-in-a-related-table/36880/9 "2022-01-18T09:14:34Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
