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
sebinantony
New Member

calculate opening balance, sum of debit/credit and closing balance within date

Hi,

 

I need help!

I have the GL transactions of all main accounts, below is the sample data :sample1.JPG

 

I want to write measures for calculating:

Opening balance: This will be sum of all transaction before the start date of the date range filter for the specific main account 

Debit : This will be  sum of all values under 'debit' for the same main account with in the the date range 

Credit: This will be sum of all values under 'credit' for the same main account with in the date range 

Closing balance: This will be calculated as sum of opening balance, debit and credit for the specific main account 

 

The resulting table should look like:

sample2.JPG

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Try this with Date Calendar and join it Accounting date

@sebinantony 

The opening is sum of debit and credit till last month

The closing is sum of debit and credit till this month

All are new measures

Debit = SUM(Table[Debit])

Credit =SUM(Table[Credit])

Opening balance = CALCULATE(SUM(Table[Debit]),filter(date,date[date] <=maxx(date,max(dateadd(date[date]),-1,Month))))
+ CALCULATE(SUM(Table[Credit]),filter(date,date[date] <=maxx(date,max(dateadd(date[date]),-1,Month))))

closing balance = CALCULATE(SUM(Table[Debit]),filter(date,date[date] <=maxx(date,date[date])))
+ CALCULATE(SUM(Table[Credit]),filter(date,date[date] <=maxx(date,date[date])))

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Try this with Date Calendar and join it Accounting date

@sebinantony 

The opening is sum of debit and credit till last month

The closing is sum of debit and credit till this month

All are new measures

Debit = SUM(Table[Debit])

Credit =SUM(Table[Credit])

Opening balance = CALCULATE(SUM(Table[Debit]),filter(date,date[date] <=maxx(date,max(dateadd(date[date]),-1,Month))))
+ CALCULATE(SUM(Table[Credit]),filter(date,date[date] <=maxx(date,max(dateadd(date[date]),-1,Month))))

closing balance = CALCULATE(SUM(Table[Debit]),filter(date,date[date] <=maxx(date,date[date])))
+ CALCULATE(SUM(Table[Credit]),filter(date,date[date] <=maxx(date,date[date])))

 

@amitchandak 

 

Hi Thanks for helping! I am able to get the measured values for debit and credit but can you please tell me how to "Try this with Date Calendar and join it Accounting date" as I am not getting the opening and closing balance values 

 

Thanks!

Sebin

Probably too late, but did you solve the calculation?    I have the same problem, please help !!!

gerardotrejogcg_0-1693857097372.png

I did calculate the timeframes to be calculated.   

_Balance Amount Transactional =
SUMX ( 'General Ledger', ABS( 'General Ledger'[Debit] ) - ABS ( 'General Ledger'[Credit] ))

_Balance Amount Transactional M-1 =
CALCULATE ( _Balance Amount Transactional,
    FILTER( ALL ( 'Date' ), 'Date'[Date] <= LASTDATE ( PREVIOUSMONTH( 'General Ledger'[TransDate] ) ) )

_Starting Balance =
VAR _FirstDate = FIRSTDATE ( ALL ( 'Date'[Date] ) )
VAR _FirstDatePrevMonth = FIRSTDATE ( PREVIOUSMONTH( 'General Ledger'[TransDate] ) )
VAR _LastDate = LASTDATE ( 'Date'[Date] ) -- LASTDATE ( 'General Ledger'[TransDate] )
VAR _LastDatePreMOnth = LASTDATE ( PREVIOUSMONTH( 'General Ledger'[TransDate] ) )
VAR _FirstTransDate = FIRSTNONBLANK ( 'Date'[Date], [_Balance Amount Transactional] )

RETURN
    IF (
        _FirstDate = _FirstTransDate,
        0,
        CALCULATE (
            [_Balance Amount Transactional],
            DATESBETWEEN ( 'Date'[Date], _FirstDatePrevMonth, _LastDatePreMOnth)
        )
    )

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.

Top Solution Authors