The phrase "to do the math" means to solve a problem or figure out a calculation using numbers and formulas. It suggests that someone needs to analyze and calculate something to find an answer or understand a situation better. Full definition
I'm married, and our property tax is more than our standard deduction, so when doing the math, the mortgage is fully deductible, as are our contributions. (money.stackexchange.com)