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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Summing values of a column until a change occurs

Hello dear community.

 

I would like to know if anyone has an idea for a Dax formula. My wish would be that the values of this column are added until my ID changes. After each ID change, the values should be added back to zero. Furthermore, it would be helpful to have some kind of counting up to this change of ID. Even if the ID is repeated, as is the case here, it should start counting again after each change.

 

Below is an example of how it should look like. The DAX formulas should be able to output the two right columns like here:

 

leovinc14_0-1628808483200.png

 

 

I would be very grateful for some ideas, as I have already tried a few things without success.

 

 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

Try calculated columns as below:

 

flag_change = 
VAR ID1 = 'Table'[ID]
VAR ID2 =
    CALCULATE (
        MAX ( 'Table'[ID] ),
        FILTER ( 'Table', 'Table'[Index ID] = EARLIER ( 'Table'[Index ID] ) - 1 )
    )
RETURN
    IF ( ISBLANK ( ID2 ), 0, IF ( ID1 <> ID2, 1, 0 ) )   // change:1 unchange:0
New ID Index = 
CALCULATE (
    SUM ( 'Table'[flag_change] ),
    FILTER ( 'Table', 'Table'[Index ID] <= EARLIER ( 'Table'[Index ID] ) )
)
SUM = 
CALCULATE (
    SUM ( 'Table'[Number of something] ),
    FILTER (
        'Table',
        'Table'[New ID Index] = EARLIER ( 'Table'[New ID Index] )
            && 'Table'[Index ID] <= EARLIER ( 'Table'[Index ID] )
    )
)    //Group by 'New Id Index' to get the accumulated value
Count = 
CALCULATE (
    COUNTROWS('Table'),
    FILTER (
        'Table',
        'Table'[New ID Index] = EARLIER ( 'Table'[New ID Index] )
            && 'Table'[Index ID] <= EARLIER ( 'Table'[Index ID] )
    )
)

 

54.png

Best Regards,
Community Support Team _ Eason
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

8 REPLIES 8
Anonymous
Not applicable

Ok, I found out that I have less RAM memory available to run some formulas. Power BI gives the error message that there is "not enough RAM to perform this operation". So I changed the first two formulas a bit to work around this problem:

 

ChangeStatus = IF('Table'[ID]=LOOKUPVALUE('Table'[ID],'Table'[Index ID],'Table'[Index ID]-1),"","changed")

 

ChangeIndex = COUNTX ( FILTER ( ALL ('Table'), 'Table'[Index ID] <= EARLIER('Table'[Index ID]) && 'Table'[ChangeStatus] <> ""), 'Table'[Index ID])

 

Inspired by this page: https://community.powerbi.com/t5/Desktop/Reinit-count-when-value-changes/m-p/205258

 

Everything works wonderfully now. I really thank you very much for your solutions! 😃👍

But does anyone have an idea how to solve this RAM memory problem without physically upgrading the laptop or PC?

 

Ashish_Mathur
Super User
Super User

Hi,

Within every ID, in what order should the addition happen?  Is there a Date column somewhere?


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

There is an additional "Index ID column" as a sequential number. And a column with a date, but this is not in the order of the index.

 

leovinc14_0-1628815142095.png

 

 

Hi,

Share data in a format that can be pasted in an MS Excel file.  The data that you share should have a Date column.


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

Thank you very much for your answers. But the order of the date is not the same as the ID. What is decisive for me is the order of the ID. The "Number of something" is actually the days until the ID change. I have updated the example to show the problem. Is there a way to create the two columns "Count" and "Sum" from the others using DAX or something similar?

 

leovinc14_0-1628851526555.png

 

Hi, @Anonymous 

Try calculated columns as below:

 

flag_change = 
VAR ID1 = 'Table'[ID]
VAR ID2 =
    CALCULATE (
        MAX ( 'Table'[ID] ),
        FILTER ( 'Table', 'Table'[Index ID] = EARLIER ( 'Table'[Index ID] ) - 1 )
    )
RETURN
    IF ( ISBLANK ( ID2 ), 0, IF ( ID1 <> ID2, 1, 0 ) )   // change:1 unchange:0
New ID Index = 
CALCULATE (
    SUM ( 'Table'[flag_change] ),
    FILTER ( 'Table', 'Table'[Index ID] <= EARLIER ( 'Table'[Index ID] ) )
)
SUM = 
CALCULATE (
    SUM ( 'Table'[Number of something] ),
    FILTER (
        'Table',
        'Table'[New ID Index] = EARLIER ( 'Table'[New ID Index] )
            && 'Table'[Index ID] <= EARLIER ( 'Table'[Index ID] )
    )
)    //Group by 'New Id Index' to get the accumulated value
Count = 
CALCULATE (
    COUNTROWS('Table'),
    FILTER (
        'Table',
        'Table'[New ID Index] = EARLIER ( 'Table'[New ID Index] )
            && 'Table'[Index ID] <= EARLIER ( 'Table'[Index ID] )
    )
)

 

54.png

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Thank you @v-easonf-msft  for your suggested solution.

 

The first formula works fine. There is a small problem with the second formula "New ID Index". The actual file has over 100,000 rows. For the DAX formula it loaded for hours without showing a result, so I had to stop. Any idea how I could solve this problem? Or could the formula be split into two or three steps so that the PC is not overwhelmed?

 

Kind regards,

leovinc14

Hi,

In the second last row, why should the answer be 5?  Why should it not remain 1?  Also, please share data in a form that can be pasted in MS Excel.


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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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