Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Jelena17
New Member

Calculating Opening and Closing Balance

Hi,

 

Need your help with calculating opening and closing balance per period that user selects. We have a table as our visualization and columns are VendorName, Balance (DebitAmount - CreditAmount) and possible 2 more columns, at least we had 2 columns, and it's opening balance and closing balance. We used 2 measures (opening and closing balance columns), the formula was : Closing Balance = SUMX(FILTER(VendorLedgerEntries, CALCULATE(MAX(VendorLedgerEntries[PostingDate].[Date]), ALLSELECTED(VendorLedgerEntries))>= VendorLedgerEntries[PostingDate]),VendorLedgerEntries[DebitAmount] - VendorLedgerEntries[CreditAmount])

 

VendorLedgerEntries is our table and VendorLedgerEntries[PostingDate] are dates of every ledger entry,

 

User picks a date from slicer, and we put a PostingDate in slicer in DateHierarchy format. Periods are year, quarter and month.

 

We tried with openingbalancemonth/year/quarter function, but didn't succeed

 

The problem is when the date is picked, our main table with vendor data is filtering, but it is not supposed to, we need all data to show.

 

Request is that we calculate starting balance from the beginning of time( in our case it is year 2018) to the first day of selected period, and closing balance is all transactions to the last day of selected period

 

Sorry for bad English, we'll send more info if you need.

 

Thank you in advance!

af9b52ff-788a-4ae3-a831-06f649497512.jpg

f207411a-b8c1-4670-8fb2-f72b0713b68f.jpg

1 ACCEPTED SOLUTION

Problem solved!

This function worked for us 

calculate( sum(VendorLedgerEntries[DebitAmount]) - sum(VendorLedgerEntries[CreditAmount]), DATESBETWEEN('Calendar'[Date],blank(),min('Calendar'[Date])))

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Jelena17 , if date table is joined with posting date a measure like

calculate( sum(VendorLedgerEntries[DebitAmount]) - sum(VendorLedgerEntries[CreditAmount]), filter(allselected('Date'), 'Date'[Date] <= Max('Date'[Date])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you for answering,

 

This is the output with the measure you sent. Still doesn't work, my guess is because of MIN function, because it can't see the dates before selected date. Example: Selected 2020/1/1, and if we use MIN(selected date), there is no values before 2020/1/1 because our slicer filters the table.

 

Then we turned off interaction between slicer and table, but it is the same. We also tried getting value from slicer, our expected value is on card visualization (1/1/2020), with selectedvalue function.

 

Do you have any suggestions about what should we do next?

 

Again, thank you in advance!

e175adac-3bd2-4f88-a1c6-b7b0b188769e.jpg

Problem solved!

This function worked for us 

calculate( sum(VendorLedgerEntries[DebitAmount]) - sum(VendorLedgerEntries[CreditAmount]), DATESBETWEEN('Calendar'[Date],blank(),min('Calendar'[Date])))

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors