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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
kbabu57
Regular Visitor

Cumulative Sum by 2 columns

Hi Folks and @Fowmy @Jihwan_Kim 

 

I have a requirement where i have to get cumulative sum by 2 columns. The below is the sample data

The thing is Final Amount is coming by Customer Number and Year 

 

YearCustomer NumberPrice AmtDiffBalance PayFinal Amount
2015123$1000-50$500$450
2016123$1000100$600-$50
2017123$1000200$200-$50
2015789$2000800$100$2700
2016789$2000700$300$3100
2017789$2000600$400$3700

 

I want to get Final Amount calculation as below:
1sr row calculation =  $1000 +(-50) - $500 = $450

2nd row calculation = $1000 + ((-50)+100) - ($500+$600) = -50

3rd row calculation = $1000 + (-50+100+200) - ($500+$600+$200) = -50

 

4th row calculation = $2000+800 - $100 = $2700

5th row calculation = $2000+(800+700) - ($100+$300) = $3100

6th row calculation = $2000 + (800+700+600) - $400 = $3700

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @kbabu57 

 

@Ashish_Mathur Good share!

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Datas"

vnuocmsft_0-1705474482708.png

 

You can create a measure. Group by customer number, and add up "Diff" and "Balance Pay".

vnuocmsft_1-1705474533004.png

Final Amount = 
CALCULATE (
    SUM ('Datas'[Price Amt]),
    FILTER (
        ALLEXCEPT ('Datas', 'Datas'[Customer Number]),
        'Datas'[Year] = MAX ('Datas'[Year])
    )
)
+ CALCULATE (
    SUM ('Datas'[Diff]),
    FILTER (
        ALLEXCEPT ('Datas', 'Datas'[Customer Number]),
        'Datas'[Year] <= MAX ('Datas'[Year])
    )
)
- CALCULATE (
    SUM ('Datas'[Balance Pay]),
    FILTER (
        ALLEXCEPT ('Datas', 'Datas'[Customer Number]),
        'Datas'[Year] <= MAX ('Datas'[Year])
    )
)

 

Here is the result

vnuocmsft_2-1705474913742.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @kbabu57 

 

@Ashish_Mathur Good share!

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Datas"

vnuocmsft_0-1705474482708.png

 

You can create a measure. Group by customer number, and add up "Diff" and "Balance Pay".

vnuocmsft_1-1705474533004.png

Final Amount = 
CALCULATE (
    SUM ('Datas'[Price Amt]),
    FILTER (
        ALLEXCEPT ('Datas', 'Datas'[Customer Number]),
        'Datas'[Year] = MAX ('Datas'[Year])
    )
)
+ CALCULATE (
    SUM ('Datas'[Diff]),
    FILTER (
        ALLEXCEPT ('Datas', 'Datas'[Customer Number]),
        'Datas'[Year] <= MAX ('Datas'[Year])
    )
)
- CALCULATE (
    SUM ('Datas'[Balance Pay]),
    FILTER (
        ALLEXCEPT ('Datas', 'Datas'[Customer Number]),
        'Datas'[Year] <= MAX ('Datas'[Year])
    )
)

 

Here is the result

vnuocmsft_2-1705474913742.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

 

Wow.. This is even better. Thank you Nono Chen

kbabu57
Regular Visitor

Hi Ashish @Ashish_Mathur 

 

1st of all , Thank you so much for replying my thread. Sorry for delayed reply as i am trying out with any options & combinations with the above pbi file which you attached. Seems like, you created a extra table called "Date" and developed the logics to achieve the requirement. Is there any way without creating extra "date" and build the logic with the existing data ?

I will take a step back. I have only customer numbers as below and want to achieve the requirement.Please provide your thoughts how can we get with the below data

Customer

Number

Price AmtDiffBalance PayFinal Amount
abc123$1000-50$500$450
abc123$1000100$600-$50
abc123$1000200$200-$50
def567$2000800$100$2700
def567$2000700$300$3100
def567$2000600$400$3700


Thanks in advance

 

You are welcome.  You must create a Calendar Table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish @Ashish_Mathur 

Thank you. Much appreciated for your help. However, i just tried without creating extra Calendar table, with the existing data that has date column, got the required output as well 🙂


kbabu57
Regular Visitor

Hi Friends, Could you please help how to write the DAX measure for the above requirement

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1705125817479.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors