Calculating total hours worked - Should I use Custom Functions?
![Ambroise](https://us.v-cdn.net/6037124/uploads/userpics/CQK66977Q335/nTGIPZ4H8MVBY.jpg)
Hi!
I want my API to return the number of "hours worked", based on some business predicates, using the data being stored in related records.
I'm sure it can be done with Xano, but I'm unsure about what component/feature to use.
Should I use a Custom Function? Or should I use something different?
In Airtable, I'd typically use a Formula field.
Answers
-
Hi,
It can be done in a couple of different ways depending on the details of your case.
Can you share some more information about how the data structure is build and in how many related tables the data about "hours worked" is stored?
-
I have a table "Traveler" and another one called "TimeCategorization", which contains the actual worked hours.
I want to return
Traveler.hoursWorked
as a computed value. In airtable, I'd use a Formula field. In Xano, I understand there is no such thing and I should rather do the calculation on all API endpoints where I want to get thehoursWorked
value.Now, I guess using a Custom Function to do this calculation is one way to go, I'm unsure if I'll have several APIs that will need it, but I'd rather write something that can be reused later easily.
-
Actually if you want to access TimeCategorization from Traveler you need to add it as an addon in your query Traveler query all records (so yes you need to do this either in background task or endopit).
By adding TimeCategorization as an addon to Traveler via table relation you will gain access to all the TimeCategorization fields. If Traveler is related to more than TimeCategorization you can connect them all as a list via addon and then sum up hours from all of them by creating a new variable for example.
There are plenty of methods to do that and this is just one of them. If I would know more about your project then maybe I would be able to guide you more specifically. Let me know if that helped.
Btw, I'n offering consultation so if you have trouble with some other things in Xano and would like to speed things up, drop me an email: pmagdanski@gmail.com
-
Thanks Pawel, that does help!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback