Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi all
I have data where payments are made against invoices. Every invoice can have one or many payment vouchers.
I have written 2 measures
OpenBal = CALCULATE([Billings] - [Collections],
FILTER(ALL(MasterDate[Date]),MasterDate[Date]<MIN(MasterDate[Date])))
ClosingBal =
var closebal = CALCULATE([Billings] - [Collections] ,
FILTER(ALL(MasterDate[Date]),MasterDate[Date]<=MAX([Date])))
But when brought in a matrix, the measure calculates line wise and the result shows like this -
March | ||||
OpenBal | Billings | Collections | ClosingBal | |
Invoice1 | 30,000 | 30,000 | 0 | |
Voucher1 | 30,000 | 18,000 | 12,000 | |
Voucher2 | 30,000 | 12,000 | 18,000 |
Both Voucher1 and Voucher2 are marked against the same invoice.
Even though total shows 0 here, the individual balances are carried over in the next few months. How can I rectify this.
Any advice/suggestion highly appreciated.
@tamerj1 @Greg_Deckler
@Rakshana Hi! You can use SUMX and FILTER to iterate through each invoice and its associated vouchers to calculate the open balance correctly:
OpenBal =
SUMX (
FILTER (
ALL ( 'YourTableName' ),
'YourTableName'[InvoiceID] = EARLIER ( 'YourTableName'[InvoiceID] )
&& 'YourTableName'[VoucherDate] < EARLIER ( 'YourTableName'[VoucherDate] )
),
'YourTableName'[Billings] - 'YourTableName'[Collections]
)
ClosingBal =
SUMX (
FILTER (
ALL ( 'YourTableName' ),
'YourTableName'[InvoiceID] = EARLIER ( 'YourTableName'[InvoiceID] )
&& 'YourTableName'[VoucherDate] <= MAX ( 'YourTableName'[VoucherDate] )
),
IF ( 'YourTableName'[Collections] < 0, 0, 'YourTableName'[Billings] - 'YourTableName'[Collections] )
)
Try, BBF
Hey thank you for your response.
But this throws a syntax error for EARLIER
Is there any other way to calculate Opening and Closing balance without it forming a circular dependency.