In quick I have 2 ways pop up in my head.
1) pivot table should be the first good solution in this case, but also depends a lot on your data structure.
2) use some kind of dynamic formula to pick the value.
Any way, both ways we need to see your data, as donald suggest you.
With your attachment, the answer will be more clear and accurate.