Duration of the next active layer.

nextActiveLayer = thisLayer;
for (i = thisLayer.index + 1; i <= thisComp.numLayers; i++) {
	if (thisComp.layer(i).active) {
		nextActiveLayer = thisComp.layer(i);
duration = nextActiveLayer.outPoint - nextActiveLayer.inPoint;
timeToFrames(duration, fps = 1.0 / thisComp.frameDuration, isDuration = true)

Apply this expression to the Source Text property of a text layer at the top of a stack. The for loop in here iterates down from the top to find the first layer that is active and gets its duration.

Parallax offset from a tracked Null

trackLayer = thisComp.layer("MotionTracked")
trackPosition = trackLayer.transform.position
trackDiff = trackLayer.transform.position.valueAtTime(trackLayer.inPoint)
trackAdd = trackPosition - trackDiff
transform.position +trackAdd*.5

I use this expression to add a parallax offset to a motion track. Apply your track to a Null called MotionTracked and crop the layer inPoint to your reference point.

Duration of layer expression

duration = outPoint-inPoint
timeToFrames(duration, fps = 1.0 / thisComp.frameDuration, isDuration = true)

Here’s a quick expression I like to use with the Numbers effect in AE to print the frame duration on the image when I need to add graphics to an edited string out. It helps with shot planing.