It's quite complex as there are several steps required .
1. A nearest search for the "Destination" airport , and obtain the 'Elevation' of that airport.
2. Calculate the "3 degree glideslope distance" to about 2,500' above that airport elevation.
3. From the aircraft's final leg cruise altitude , subtract (2,500' + airport elevation) to obtain " Initial let down Height"
4. determine "Let down distance" by dividing "Initial let down height" by the average VSI to obtain "Let down Time".
"Let down time" multiplied by GS = "Let down distance"
5. "3 degree glideslope distance" plus "Let down distance" = "Total distance from TOD to airport"
6. In your case add 40 nm to "Total distance from TOD to airport" as the distance to trigger your advisory alarm .
Notes :
- The GS (Groundspeed) would be the cruise GS , unless a descent GS is nominated .
- The airport elevation is important as not all airports are at or near sea level , therefore it needs to be accounted for.
- The normal glideslope for approaches is 3 degrees , however the Let down phase would rarely match that angle , thus let down
needs to be treated separately.
Cheers
Karol
PS ;
The following link might be of interest ,
http://www.fsdeveloper.com/forum/threads/storage-of-gps-variables.433868/
specifically refer to reply #33 on the second page , covering Intercept position Height
above runway.