# Repeating Group Calculation Help?

Hey Guys,

I hope this is something that we can easily do. I have a repeating group that lists hours going across. The hours are calculated from an In and Out field. Here the hours are calculated in the text field in the repeating group. What that means is there isnt any calculation being done on the fields themselves. That makes it difficult for me to figure out how to sum the hours. Please see this video for more information.

Does anyone have any ideas?

1 Like

I just replicated exactly what you have described by using disabled input fields (as opposed to text elements) formatted as integers for the cells in which the calculations are being done, and then the cell with the sum is also a disabled input field that is just the first cell plus the next cell plus the next cell and so on.

Iâ€™m sure there are a number of other ways to do what you are trying to do, but maybe that way would work for you?

Bestâ€¦
Mike

Hey @mikeloc Thank you for the reply. Im not so sure how to begin with that?

Is it possible to show me in loom what you were able to accomplish?

All the best,
Benjamin

Can you try format as hours?
I think only Type of content:numberâ€™s repeating group can use â€śsumâ€ť function.
And date format can change to number by format as hours.

@ben4

Is this what youâ€™re trying to do?

1 Like

Hey @lantzgould ,

Thank you for looking into this with me. I appreciate any help. That is what I am trying to do, however, there is still another piece that needs to be looked at. I can better explain it in a video. There is also something else that I am looking for help with on another thread that you might know. Here is hoping!

My apologies, @ben4â€¦ when I responded the first time, I didnâ€™t understand exactly what you are trying to do. After watching the second video, it looks like when you enroll a student, you create three attendance records, and you are trying to get the hours from each attendance record to show in separate columns in the appropriate studentâ€™s row. Finally, you want the hours from each column in a studentâ€™s row to display as a sum at the end of the row. So, if I have all of that correct, it should look something like this?

Is that the idea?

Bestâ€¦
Mike

@mikeloc Absolutely!! Was that easy?? ha! I just want to ask, are those hours being totaled from a date in - out. I donâ€™t know if that really matters, just wondering.

@ben4 It wasnâ€™t difficult to get it working once I understood what you are trying to do. Kudos to you for including those videos, by the wayâ€¦ they are super helpful!

Yes, the hours are being calculated from a date in/out, although I chose to do the calculations when the records are created and store the hours in the db. I also have a separate table for the student (separate from the actual attendance records, that is). So, when a name is entered and the button is clicked, I create a record in the student table, and then I create three records in the attendance table for that student. With that structure in place, I have a main repeating group to show the students, and I have a repeating group inside of the main repeating group to show the attendance hours for each student.

Anyway, thatâ€™s the gist of it. If any of that sounds like it would be useful to you and you need more details, just let me know and I will be happy to grab some screenshots.

Bestâ€¦
Mike

@mikeloc Hey Thank you. I have one question.

You mentioned that you store hours in the DB - That sounds like the solution to my next issue. See this video: https://www.loom.com/share/43f94e389c824b5c8b6c9a05fe6f8bc3

Im a little lost on how to write a calculation to a field after its been calculated in a text element.

BTW I basically live in the loom app, I am making videos all day long, it makes development so much easier for me hah!

@ben4 In the attendance datatype, I created an hours field with a field type of number. I populate this field as follows:

When the Enroll Student button is clicked, I create a student record. The next step in the workflow creates the first attendance record like so (ignore the time in/out valuesâ€¦ I just threw something in there to get some data):

Now that the attendance record has been created and it has values for time in/out, the next step in the workflow makes a change to the attendance record to calculate and populate the hours field like so:

Do you think that would work for you?

Bestâ€¦
Mike

Hey @mikeloc,

I think that is 50% of the way there. I feel bad for having you do all this back and forth with me. Can you please take a look at this video and let me know if this helps you understand that last hurdle:

All of this is to accomplish one thing, that is the totaling of hours in a sum text. Thing is when a class day has more than 7.5 hours we want the system to automatically subtract 1 hours for break time. That conflicts with the sum, obviously. Using your method of writing the hours to the DB would solve this issue, just cant get one aspect to work, per the video.

Thank you Mike!

Benjamin

@ben4 No worriesâ€¦ happy to try to help!

So, in the teacher view, the teacher has to click those check in and check out buttons, right? If so, couldnâ€™t you make changes to the associated attendance record when the check out button is clicked and calculate/populate the hours field at that time since you have both a time in and time out value then?

Bestâ€¦
Mike

Hey @mikeloc That worked. ONE MORE ISSUEEEEE haha!

Now that its a number field, its rounding the calculation to the nearest number. How can I undo that? I have tried as much as I know.

All the best,
Benjamin

@ben4 Happy to hear that worked!

Can you use rounded to at the end of the calculation to get what you want?

Bestâ€¦
Mike

I dont think that will work, unless you can round to the nearest 1/4 of an hour or 1/2 half of an hour. The time picker does quarter hour increments.

What happens if you get rid of rounded to and just format it as a number with two decimal places?

See this video:

Hmmâ€¦ you are showing the formatting on the display field, but are you doing any formatting in the workflow when you calculate and save the hours to the db? If you try formatting to two decimals places there, does that work?

It wonâ€™t let me format it in the workflow because that turns it to text??