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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Cumulative sum by date by condition

Hi, 

 

I have a table with payments at different dates, associated with different conditions : 

 

DateSumCondition
01/01/20185A
01/01/201820B
02/01/201810B
02/01/201820B
03/01/201810A
03/01/201820A
04/01/201815B

 

I would like to calculate the cumulative sum by date, by condition, such as : 

 

DateSumConditionCumulative Sum
01/01/20185A5
01/01/201820B20
02/01/201810B30
02/01/201820B50
03/01/201810A15
03/01/201820A25
04/01/201815B65

 

I found this in a similar post : 

Cumulative Sum=
CALCULATE (
SUM (Table[Sum]), FILTER (ALL (Table[Date] ),Table[Date] <= MAX ( Table[Date]))) 

 

But I don't see how to adapt to my case, so it takes in account the condition. 

Any ideas?  

 

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

hi, @Anonymous

After my research, you could do these as below:

First is there some errors in your expected output “Cumulative Sum”

for 02/01/2018 condition B, why one row is 30 and another is 50

but 03/01/2018 condition A, why one row is 15 and another is 25

please check the expected output “Cumulative Sum”

 

and I have provided two formula for you to refer to:

result 1 = 
CALCULATE (
    SUM ( 'Table'[Sum] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Condition] = EARLIER ( 'Table'[Condition] )
            && 'Table'[Date] < EARLIER ( 'Table'[Date] )
    )
)
    + 'Table'[Sum]
result 2 = 
CALCULATE (
    SUM ( 'Table'[Sum] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Condition] = EARLIER ( 'Table'[Condition] )
            && 'Table'[Date] <= EARLIER ( 'Table'[Date] )
    )
)

Result:

10.JPG

 

here is pbix, please try it.

https://www.dropbox.com/s/wqt1qi8hphipnmk/Cumulative%20sum%20by%20date%20by%20condition.pbix?dl=0

 

Best Regards,

Lin

Community Support Team _ Lin
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

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi, @Anonymous

After my research, you could do these as below:

First is there some errors in your expected output “Cumulative Sum”

for 02/01/2018 condition B, why one row is 30 and another is 50

but 03/01/2018 condition A, why one row is 15 and another is 25

please check the expected output “Cumulative Sum”

 

and I have provided two formula for you to refer to:

result 1 = 
CALCULATE (
    SUM ( 'Table'[Sum] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Condition] = EARLIER ( 'Table'[Condition] )
            && 'Table'[Date] < EARLIER ( 'Table'[Date] )
    )
)
    + 'Table'[Sum]
result 2 = 
CALCULATE (
    SUM ( 'Table'[Sum] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Condition] = EARLIER ( 'Table'[Condition] )
            && 'Table'[Date] <= EARLIER ( 'Table'[Date] )
    )
)

Result:

10.JPG

 

here is pbix, please try it.

https://www.dropbox.com/s/wqt1qi8hphipnmk/Cumulative%20sum%20by%20date%20by%20condition.pbix?dl=0

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Lin, 

 

What is the difference between result 1 and result 2

 

Regards,

Sai

Anonymous
Not applicable

Hi Lin, you are right about the error in my cumulative sum. Your formula 'result 2' works perfectly, thank you very much! 

Stachu
Community Champion
Community Champion

the code you posted should work fine as long as you put the Condition in the visual - e.g. in rows



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.