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
aqsasaleem
Frequent Visitor

Calculate balance from debit and credit foe each customer

I am trying to calculate Total balance from debit and credit columns. but my formula is not adding debit values and subtracting credit values it's showing same value in balance. it should be customer and date wise (date from older to newer). I will show one customer at a time in my report on user selection based.

 

aqsasaleem_0-1704027522182.png

 

1 ACCEPTED SOLUTION

@aqsasaleem 

Try this measure:

Balance =
CALCULATE (
    SUM ( cl_resultset[md_debit] ) - SUM ( cl_resultset[md_credit] ),
    WINDOW (
        1,
        ABS,
        0,
        REL,
        SUMMARIZE (
            ALLSELECTED ( cl_resultset ),
            cl_resultset[md_date],
            cl_resultset[refernce number]
        )
    )
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

6 REPLIES 6
Fowmy
Super User
Super User

@aqsasaleem 

Please try this measure:

Balance =
CALCULATE ( [Debit Balance], tablename[date] <= MAX ( tablename[date] ) )
    - CALCULATE ( [Credit Balance], tablename[date] <= MAX ( tablename[date] ) )



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy I used your formula it's working but where dates are same (Transactions on same date) it is grouping values. any solution?

 

Formula is 

Balance =
CALCULATE (
    CALCULATE ( SUM ( cl_resultset[md_debit] )
        - CALCULATE ( SUM ( cl_resultset[md_credit] ))),
    FILTER ( ALL ( cl_resultset[md_date], cl_resultset[cl_type], cl_resultset[md_name], cl_resultset[md_description]), cl_resultset[md_date] <= MAX ( cl_resultset[md_date] ) )
)
 
and result is
 
aqsasaleem_0-1704181393542.png

 

@aqsasaleem 

Try this measure:

Balance =
CALCULATE (
    SUM ( cl_resultset[md_debit] ) - SUM ( cl_resultset[md_credit] ),
    WINDOW (
        1,
        ABS,
        0,
        REL,
        SUMMARIZE (
            ALLSELECTED ( cl_resultset ),
            cl_resultset[md_date],
            cl_resultset[refernce number]
        )
    )
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy Thank you so much it's working 😊

Hi, @aqsasaleem 

 

try below

Balance =
var a = MAX ( tablename[date] )
var b = CALCULATE ( [Debit Balance], tablename[date] < MAX ( tablename[date] ) )+a
var c = CALCULATE ( [Credit Balance], tablename[date] <= MAX ( tablename[date] ) )+a
return
b-c
salvalcaraz
Frequent Visitor

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.