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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Kudoed Authors