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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
mohd89ali
Frequent Visitor

calc balance from debit and credit

Hi all, 

 

i want to create some reports from the trial balance. basically, I only have the debit and credit for each account in a practical month.

 

This is a sample Data of what i work with. 

 

AccountTypeSMH 101110 Stock Valuation Account SMHSMH 101120 Stock Interim Account (Received) SMHSMH 101130 Stock Interim Account (Delivered) SMHSMH 101200 Account Receivable SMH
10/01/19Debit882.112 922.1067726.3
10/01/19Credit927.815876.941940.0357726.3
11/01/19Debit5502.0556360.948951.3937069.4
11/01/19Credit5451.155476.6581213.6267069.4
12/01/19Debit1140.251 635.4996345.95
12/01/19Credit634.4491138.361940.9516345.95
01/01/20Debit1051.178 1323.258404.292
01/01/20Credit1326.6921048.7231325.0668404.292
02/01/20Debit325.404 811.1785257.46
02/01/20Credit815.807298.938811.1785257.46
03/01/20Debit223.631 357.8812443.36
03/01/20Credit360.137222.627357.8812443.36
04/01/20Debit912.719 203.7521248.94
04/01/20Credit203.752912.719203.4571248.94
05/01/20Debit852.886 788.0354857.3
05/01/20Credit826.584843.212782.2484857.3
06/01/20Debit  20.581112.3
06/01/20Credit20.581 12.275112.3

 

 

First of all, I want to calc the balance of each account. by default, PowerBi would sum the debit and credit which is wrong, I want the balance to be debit minus credit. 

one way is to multiply the credit values by -1 to make them negative. 

or by adding a balance row with each date that will calculate debit - credit. 

 

could you help me with that pleases? 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @mohd89ali ,

 

Select the first and second column and then unpivot all others:

 

Now add the following measure:

Balance =
CALCULATE (
    CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Type] = "Debit" )
        - CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Type] = "Credit" );
    FILTER ( ALL ( 'Table'[Date] ); 'Table'[Date] <= MAX ( 'Table'[Date] ) )
)

Then just use it in your visualizations.

 

You should create a calendar table to use on your calculations instead of the actual table, but it also works as you can see.

 

Please see attach PBIX file.

I had to make some change on the date column due to my regional settings in your case you can use your date column as no need for the additional steps before the unpivot ( I have marked them as not needed).


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

5 REPLIES 5
MFelix
Super User
Super User

Hi @mohd89ali ,

 

Select the first and second column and then unpivot all others:

 

Now add the following measure:

Balance =
CALCULATE (
    CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Type] = "Debit" )
        - CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Type] = "Credit" );
    FILTER ( ALL ( 'Table'[Date] ); 'Table'[Date] <= MAX ( 'Table'[Date] ) )
)

Then just use it in your visualizations.

 

You should create a calendar table to use on your calculations instead of the actual table, but it also works as you can see.

 

Please see attach PBIX file.

I had to make some change on the date column due to my regional settings in your case you can use your date column as no need for the additional steps before the unpivot ( I have marked them as not needed).


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





thank you very much for your help. 

I have one more issue, the sales formula is the other way around, its credit minus debit.

I have created a separate measure filtered by the account that calc the value and multiplies it by -1. 

Sales =
[Balance for SMH 200000 Product Sales SMH] * -1

is there a way to directly change it from the balance measure?

Hi @mohd89ali ,

Balance for SMH 200000 Product Sales SMH

 

Based on my experience the best way is to do one of two things:

 

  1. Change the signal on the query editor for that account
  2. Split this into auxiliary measures:
Correct balance value = IF(SELECTEDVALUE('Table'[Account])="Balance for SMH 200000 Product Sales SMH";-[Balance];[Balance])


Final_Calculation = SUMX('Table';[Correct balance value])

 

Then use the final calculation on your calculations and settings.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Hi @MFelix , 

 

i could not make your measure work with me. 

 

download pbix  

Hi @mohd89ali ,

 

Your measure should be:

 

Correct balance value = IF(SELECTEDVALUE('Table'[Account]) IN { "SMH 200000 Product Sales SMH" },- [Balance],[Balance])

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.