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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MPR
Advocate I
Advocate I

Calculate balance of account

Hello,

 

I am new to this forum and fairly new to Power BI so please excuse my ignorance.  I have a problem with a DAX formula that is killing me.  

 

I am trying to calculat a current balance of a bank account.  I was hoping there would be a way to upload my pbix file but I don't see how to do that so I will try to explain.  

 

Following is a table of data:

 

 

IndexDateAmountBalance
2654/19/2018$1,214.55 
2644/19/2018$2,436.80 
2634/19/2018$1,211.35 
2624/19/2018$459.00 
2614/19/2018$811.00 
2604/19/2018$986.59 
2594/19/2018($35.00) 
2584/19/2018($1,549.73) 
2574/19/2018$2,821.25 
2564/19/2018$7,976.00 
2554/18/2018$1,182.07$91,517.55
2544/18/2018$2,156.25$93,673.80
2534/18/2018$1,258.95$94,932.75
2524/18/2018$2,096.66$87,594.94
2514/18/2018$1,490.82$89,085.76
2504/18/2018$1,249.72$90,335.48
2494/18/2018$181.48$97,201.23

 

This info assumes today is Apr 19.  With this data, I am trying to build a couple of formulas.  

 

First is a formula that provides the balance through yesterday.  For today's (Apr 19) transactions, it won't show the balance because the transactions are still pending.  To get yesterday's balance (in this example, I am trying to get $91,517.55), I created two formulas.

 

First, I wanted to get the max index so I get the correct balance>

 

Max Index = CALCULATE(MAX('Statements'[Index]),FILTER('Statements','Statements'[Balance] <> BLANK()))

 

Then, using the max index, I want to get the balance ($91,517.55).  This is the formula that I think I am getting wrong.  

 

 Bank Balance = CALCULATE(MIN('Statements'[Balance]),FILTER('Statements','Statements'[Index] = [Max Index]))

I am still working through how the nuances of the contexts and how calculate changes them but my gut is telling me there is a context problem with this formula.

 

Once I get yesterday's balance, I can add the pending amounts to get the actual balance.  For that formula, I have 

 

Pending = CALCULATE(SUM(Statements[Amount]),FILTER('Statements','Statements'[Balance] = BLANK()))

I think that formula is okay.  I am getting the correct result with that.

 

I would really appreciate someone's help letting me know what I am doing wrong in the second formula.

 

Thanks,

MPR

1 ACCEPTED SOLUTION
drewlewis15
Solution Specialist
Solution Specialist

You can probably continue using your evaluation to find the last ending balance by checking to see if balance is simply blank, but I added a custom column in the query editor to identify if the record is "pending" or "posted".

 

if Balance = null then "Pending" else "Posted"

 

I then created the following measure, which seems to be grabbing the last ending balance.

 

Last Ending Balance = LOOKUPVALUE(Statements[Balance], Statements[Index], (CALCULATE(MAX(Statements[Index]), FILTER(Statements, Statements[Status] = "Posted"))))

 

Probably a more efficient way to write this, but it is getting the correct amount in my testing.  From there, your other measure should be able to add the pending total to the Last Ending Balance total.

View solution in original post

2 REPLIES 2
MPR
Advocate I
Advocate I

Thanks drewlewis15.  That did it.  

drewlewis15
Solution Specialist
Solution Specialist

You can probably continue using your evaluation to find the last ending balance by checking to see if balance is simply blank, but I added a custom column in the query editor to identify if the record is "pending" or "posted".

 

if Balance = null then "Pending" else "Posted"

 

I then created the following measure, which seems to be grabbing the last ending balance.

 

Last Ending Balance = LOOKUPVALUE(Statements[Balance], Statements[Index], (CALCULATE(MAX(Statements[Index]), FILTER(Statements, Statements[Status] = "Posted"))))

 

Probably a more efficient way to write this, but it is getting the correct amount in my testing.  From there, your other measure should be able to add the pending total to the Last Ending Balance total.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.