The formal way of expressing gratitude for someone taking care of a matter or dealing with a situation would be:
"Thank you for handling the matter" or "Thank you for addressing the situation."
Both of these expressions convey appreciation in a professional and formal manner. By using "thank you" and acknowledging the specific action (handling the matter or addressing the situation), you show respect and gratitude for their efforts and competence in resolving the issue.