After a five-year battle with the Canada Revenue Agency, the parliamentary budget office is finally being promised the data needed to evaluate the amount of revenue Ottawa loses each year due to offshore tax havens and other tax avoidance schemes.

The budget office has been demanding the data since December 2017 and has even threatened court action to get it. But, until now, the agency has refused to provide it, citing confidentiality of tax records.

Prime Minister Justin Trudeau announced Monday that a deal has finally been struck between the agency and the budget officer.

"An agreement has been concluded with the parliamentary budget officer and will provide this data in a way that will ensure the protection of personal information of Canadians by the end of the month," he told the House of Commons.

Jean-Denis Frechette, the parliamentary budget officer, had given the agency until Feb. 28 to turn over the data before pursuing other options.

He welcomed the news of a deal Monday, but reserved the option of going to court if the data that's handed over turns out to be less than advertised.

"So, yes, that would be something that could be considered, depending on the outcome of Feb. 28," Frechette said in an interview.

He said he has no problem with Trudeau's caveat that the handover of information will be done in a manner that will protect the personal information of taxpayers, noting that his office has always said it wants "anonymized" data only.

If his office gets all the information it has been seeking, Frechette guessed it might take six to 10 months to crunch the numbers and come up with an estimated "tax gap" — the difference between the amount of tax revenue that should have been collected in a year and what was actually collected. But the time frame will depend on the quality of information the Canada Revenue Agency provides.

"If they send me ... paper version of all their files in boxes, of course it will take a long time," he said. "It's difficult for me to guess."

The Conference Board of Canada has estimated that tax evasion and tax avoidance cost the federal treasury anywhere between $8.9 billion and $47.8 billion annually.

The Trudeau government has been under pressure to allow the budget officer to do a more precise, independent estimate of the tax gap, particularly in the wake of the so-called Paradise Papers — a second major leak detailing how hundreds of billions of dollars from around the world are sheltered in offshore tax havens, at the expense of numerous countries' treasuries.

A number of other countries, including the United Kingdom and the United States, have long provided estimates of their tax gaps but Canada has refused to follow suit, until now.

Until the size of the Canadian problem is known, Frechette said it's impossible to know how to fix it.

The Trudeau government has earmarked almost $1 billion over two years to crack down on offshore tax evasion.

But while political attention has focused on the suspected billions lost to tax havens, Frechette said there are other factors at play, including Canadians involved in the underground economy who do not report their income and those who make honest errors in interpreting complicated tax rules.

The Canada Revenue Agency has recently estimated that about $4.5 billion in GST revenue and about $8.8 billion in personal income tax revenue has gone uncollected annually. There has been no comprehensive estimate of the revenue lost from taxes on all sources, including corporations and trusts that are most likely to benefit from offshore tax shelters.