Hi Anne,
Some corrections to your formulas:
If you have RPKM (single-end data) or FPKM (paired-end data) computed for a set of genes or transcripts you can convert to TPM with
TPM = FPKM / (sum of FPKM over all genes/transcripts) * 10^6
The formula is the same for RPKM.
If you have read (single-end) or fragment (paired-end) counts, you can compute TPM by first computing RPKM (or FPKM) and then using the formula above for TPM.
An interesting aspect of the math here is that
sum of FPKM over all transcripts = 10^6/(expression weighted mean transcript length in kb)