This is the iterator I use and it doesn't filter hidden units out.
Unit Group -For each unit armyUnit in (Any units in (Entire map) owned by player Any Player matching Excluded: Structure, Worker, Resource (Raw), Resource (Harvestable), Missile, Item, Dead, Hallucination, Summoned, Map Boss, with at most Any Amount) do (Actions)
addUnitCost(armyUnit,costAccums[(Owner of armyUnit)])
I found the function I needed. It is UnitCargoGroup(unit: Unit): UnitGroup
And this is the iteration I use to accumulate the army value of the units inside Nydus Networks:
------- Units inside nydus networks are not included in the `Entire Map` region. So their upkeep is treated sepparately here.
Now the mod calculates the army value correctly.
Thank you MaskedImposer for mentioning the word "cargo". It helped me to find the function I needed.