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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Antmkjr
Post Patron
Post Patron

Cumulative subtraction based on condition

 

 

 

 i want to create a calculated column "Expected ", which is obtained by Cumulative Subtracting Advance Paid and Amount Due Remaining, ie. Subract Advance from Expected as long as its subtractable. 

 

 

How to do this as a calculated column in DAX.

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Antmkjr,

 

You may try these two Calculated columns.

Advance Revised Calculated Column =
VAR original =
    CALCULATE (
        MAX ( 'Table'[Advance Paid] ),
        ALLEXCEPT ( 'Table', 'Table'[Project] )
    )
VAR cumulative =
    CALCULATE (
        SUM ( 'Table'[Amount  Remaining] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project] ),
            'Table'[Ins No] > 1
                && 'Table'[Ins No] <= EARLIER ( 'Table'[Ins No] )
        )
    )
VAR diff = original - cumulative
RETURN
    IF (
        diff > 0,
        diff,
        IF ( ABS ( diff ) < 'Table'[Amount  Remaining], diff, BLANK () )
    )

 

Expected Amount Remaining Calculated Column =
VAR PrevPaidAmount =
    CALCULATE (
        MAX ( 'Table'[Advance Revised Calculated Column] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project] ),
            'Table'[Ins No]
                = EARLIER ( 'Table'[Ins No] ) - 1
        )
    )
VAR diff = PrevPaidAmount - 'Table'[Amount  Remaining]
RETURN
    IF (
        ISBLANK ( 'Table'[Advance Revised Calculated Column] ),
        'Table'[Amount  Remaining],
        IF ( diff >= 0, 0, ABS ( diff ) )
    )

 

The result looks like this.

vcazhengmsft_0-1663922282461.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

1 REPLY 1
v-cazheng-msft
Community Support
Community Support

Hi @Antmkjr,

 

You may try these two Calculated columns.

Advance Revised Calculated Column =
VAR original =
    CALCULATE (
        MAX ( 'Table'[Advance Paid] ),
        ALLEXCEPT ( 'Table', 'Table'[Project] )
    )
VAR cumulative =
    CALCULATE (
        SUM ( 'Table'[Amount  Remaining] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project] ),
            'Table'[Ins No] > 1
                && 'Table'[Ins No] <= EARLIER ( 'Table'[Ins No] )
        )
    )
VAR diff = original - cumulative
RETURN
    IF (
        diff > 0,
        diff,
        IF ( ABS ( diff ) < 'Table'[Amount  Remaining], diff, BLANK () )
    )

 

Expected Amount Remaining Calculated Column =
VAR PrevPaidAmount =
    CALCULATE (
        MAX ( 'Table'[Advance Revised Calculated Column] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Project] ),
            'Table'[Ins No]
                = EARLIER ( 'Table'[Ins No] ) - 1
        )
    )
VAR diff = PrevPaidAmount - 'Table'[Amount  Remaining]
RETURN
    IF (
        ISBLANK ( 'Table'[Advance Revised Calculated Column] ),
        'Table'[Amount  Remaining],
        IF ( diff >= 0, 0, ABS ( diff ) )
    )

 

The result looks like this.

vcazhengmsft_0-1663922282461.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.