How To Calculate "Distance From" to Reach A SUM/Total Distance For Travel Itinerary?

I’m trying to save a total distance for a travel itinerary that is infinite in the sense it can be multiple stops, departures and destinations.

How can I set the system to calculate the distance between EACH departure and arrival point in the itinerary in miles and save it as a number in a custom state?

Having a hard time grasping this one.

Thanks

I have to make a few assumptions on your setup, so I’ll provide 2 options:

  1. Here’s an example for when an button is clicked to add a new location to a repeating group.

When button is clicked > set state on Page’s Total Distance > Value = Page’s Total Distance + New Location’s address’s distance from Repeating Group :last item’s address

  1. Example for saving the distance between each leg and using that to sum.

When button is clicked > make change to new leg, “distance from previous leg” = This leg’s address’s distance from Repeating Group’s list of Legs (or search for legs in this itinerary) :last item’s address. Then use a text element to display a list of all legs’s address :sum

Lots of assumptions… if you want to share a little more about your structure, I can help with the route that makes the most sense.

2 Likes

Thanks for this help this is excellent.

The issue I have is that the fields can be changed at any point and the user can also add an unlimited number of ‘legs’ which will need to trigger a change to the group which holds the custom state “total distance in miles” inside of it.

Right now i can’t figure out how to keep the total distance state SET correctly based on the current entries for the to/from fields inside of the repeating group which can grow to an infinite number of legs.

Something like an if change is detected then re-calculate the to/from distances of every leg inside of the list of legs inside of the repeating group would be good and set this as the state.

Are these legs being saved to the database in any way?

1 Like

No. I’m trying to stay away from auto binding. So I keep everything in a custom state list on a group.

Correction: they are being created, but they aren’t auto bound.

Right now as fields are changed the list of legs in the custom state is changed/updated to the new value. I don’t know how to run a new calculation every time a change is made through to add/subtract miles/distance based on the new values.

Ok, is there any way you can share a link? It sounds very tricky because you’re keeping the whole list in a custom state. I see what you want to do though - edit the leg to a completely different location, which changes all distance calculations.

The easiest way to achieve this is to save the distance between the current leg and the leg right before it, which would also mean the saving each leg’s order in the itinerary. Easier doing it all in the database (not necessarily with auto-binding, but essentially the same effect of creating a workflow to make these changes, which would allow you to re-calculate).

But anyway… is it possible to share a link?

1 Like

I used an text input inside of the repeating group cell to dynamically calculate the distance between the to/from of that Leg and it worked fine. Auto-updates based on the user’s new change. :slight_smile:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.