[Solved] Adding a Formula Field in a Database collection or DataSet?

I have a code field in the database called “TYEPID”. It contains code values eg. “HUM”;”IND”,”UNIV”. I have added a table type list in a page. The table is linked to a database. I would like to display “Humanoid” if code is ‘HUM”, “Industry” if code is “IND” and “University” if code is “UNIV”.

I could not find a formula option in Database field or Dataset. Can this be done?

1 Like

Hey Yashika,

Sounds to me like you should be using a data hook .

Hello Sam,

I could not understand much from the brief description of Data Hook in the link provided (without any reference to examples)

Would you have some pointers to example code of how this can be done?

Hey there,

Since my last post we’ve added a new article that should help you out a bit more. Take a look here: Velo Tutorial: Calculating and Displaying Collection Data | Help Center | Wix.com.

This worked great! Thank you Sam.

So, I’m confused as to how to do simple calculations in a table using data hooks. Writing formulas in excel or google sheets is easy, but I haven’t grasped the concept of how to do this with code. All I really want is to have some columns in a collection calculate their value based on two (or more) other columns (fields) in the table.

Hi Wes,
Did you solve this in the end? Im trying to create a collection and then add a field to put a formula of eg. column A - column B . I am actually running a food online business and want to introduce meal packages. So when a customer buys a package, they actually buy an amount upfront which are like credits. So every time they buy a meal, i want to deduct the meal from the credits they have and i want to be able to show the balance on the members page. Were you able to solve that problem?

Hi,

I think my challenge is similar to this one and was hoping someone on this forum may have found the answer…

I’ve added a ‘sum’ column to my dataset called ‘MemberGreenPoints’ as you can see below, and am just wanting to add some code that will automatically add the sum of the ‘Biking Points OandA’, ‘Coffee Cup’, ‘Economic OandA’ and ‘Water Bottle OandA’ values.

Any idea’s on what this code should look like please? And is it a hook I need or code added into the page/site code panel?

Thanks,
Jobbo

i am looking for something similar but for getting 10% of a certain value into a certain field

Same. I’d like to create an expiration date for a data element without writing a lot of java. If expiration date is before today store “EXPIRED” in field that can be used to filter.

I haven’t been able to get the data hooks to actually work for me. I followed the instructions exactly and nothing. My issue is like the above one, when selecting an item I want a number value to be put in a calculated variable field.

@yashika could you please explain how did you solve it with data hooks? Is the solution still working?