Provide a sample of the data you have and the result you want. Formulas are specific. Without the specifics, there is no formula to talk about.
Nonetheless, I surmise you need a lookup formula, the choice of which depends on the specifics you provide.