I don’t get how you could count that. Usually density of pixels on the texture per unit on the mesh is counted the other way around, like 512 pixels is 1 meter or something like that. Then it is considered as 512 pixels / 100 cm = 5,12 px/cm and it is called texel density.
This is closer to what texel density is and what is done by some quite useful addons like TexTools > UV Layout > Get / Set Pixel per unit ratio (in the UV editor). Then you pick density from one mesh you count texel density for and apply it for all others getting the same level of details on the textures. See TexTools thread for more info (it has way more functionality that this).
Generally Ctrl+A in Edit mode in UV editor does the same, it equalizes scale of UV islands to make resulting density the same however it can’t use value from one island to others as reference, it makes kind of averaged value instead.