Opening / Closing Balances in reports having Financial Dimension Filters

Dear All,

Version AX 2009.

I have to make a report - Trial Balance. We have Branches as Financial Dimension. User will provide Date Range and Branch Dimension as an input to the report. As far as single dimension is concert, the report is printing correct. But here the challange is that user can input Branch Dimension in any manner. I mean he can see Trial Balance for singh branch, 3 branches, range of branches, all branches excluding any 4 branches etc. If we apply these type of filters we use something like… “103,105,110” (to see Trial Balance of three branches) or “101…110” (to see TB of branch code 101 to 110) or “!103,!105,!110” (to see TB of all branches excluding 103,105,110) in advance filter.

But how to apply this type of filter through coding ? My report have LedgerTable as a DataSource. Opening, Debit, Credit and Closing Balances is being printed through display method which is written in LedgerTable table.

As of now I am using select query like " Select sum(AmountMST) from ledgerTrans Where
ledgerTrans.AccountNum == this.AccountNum &&
ledgerTrans.Dimension[4] == financialDimId &&
ledgerTrans.TransDate >= FromDate &&
ledgerTrans.TransDate <= ToDate &&
ledgerTrans.AmountMST > 0;

for Debit Transaction for the period and similar query for calculating Opening, Credit and Closing Balances.

I am stuck here on applying this type of filter on Dimension[4] (which is Branch Dimension here).

Need your help on this.