cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Regular Visitor

Cumulative sum by row with more values per day

Hello, I'm struggling with a cumulative sum issue. I'm simplifiying the scenario here, however I have a table with date, accounting document reference, reason of accounting movement and amount. I want to create a measure which calculates the cumulative sum of the amount for each row,  without grouping the movements that share the same date.
The following pictures shows what I want. Look how despite 3 rows share the same date, the cumulative sum is calculated for each row.

I've tried several filter functions, without reaching the result. The following measure doesn't make the job, since the cumulative sum is grouped for the 3 rows sharing the date.

Cumulative sum =
VAR MaxDate =
MAX( ' Calendar'[Date] )
VAR CumulativeSum =
CALCULATE(
SUM( 'Table'[Amount ),
ALL( 'Table'[Document] ),
ALL( 'Table'[Reason] ),
'Calendar'[Date] <= MaxDate
)
)
RETURN CumulativeSum

This is the result of the previous measure, and it's not what I want.

1 ACCEPTED SOLUTION
Community Support

Thanks for the reply from @some_bih , please allow me to provide another insight:
Hi  @DataAnalystEvo ,

In your data you have the same date, so in the calculation it will add all the values for the same date 2022.4.30 as one, you can consider creating an Index that assigns a separate label to each row.

There are two ways to create an Index, one on Power Query and the other way you can follow the steps below

In Power Query -- add Column – Index Column – From 1.

Here are the steps you can follow：

1. Create calculated column.

Index =
var _search=SEARCH(".",'Table'[Document],1)
return
VALUE(RIGHT(
[Document],
LEN([Document]) - _search))

2. Create measure.

Measure =
SUMX(
FILTER(ALL('Table'),
'Table'[Index]<=MAX('Table'[Index])),[Amount])

3. Result:

Best Regards,

Liu Yang

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

3 REPLIES 3
Community Support

Thanks for the reply from @some_bih , please allow me to provide another insight:
Hi  @DataAnalystEvo ,

In your data you have the same date, so in the calculation it will add all the values for the same date 2022.4.30 as one, you can consider creating an Index that assigns a separate label to each row.

There are two ways to create an Index, one on Power Query and the other way you can follow the steps below

In Power Query -- add Column – Index Column – From 1.

Here are the steps you can follow：

1. Create calculated column.

Index =
var _search=SEARCH(".",'Table'[Document],1)
return
VALUE(RIGHT(
[Document],
LEN([Document]) - _search))

2. Create measure.

Measure =
SUMX(
FILTER(ALL('Table'),
'Table'[Index]<=MAX('Table'[Index])),[Amount])

3. Result:

Best Regards,

Liu Yang

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

Regular Visitor

Thank you @v-yangliu-msft .

As I said, I was oversimplifiyng the scenario in my post. I have a huge fact table with a very complex data model, and more filters are included in the measure I have to build. Indeed, I had already tried with a Power Query-calculated index column, but it didn't work, the measure was extremely slow and thus ineffective. However, I found that your advice is effective. For some reason still not so clear to me, SUMX + FILTER(Table) is way more quick and I achieved my goal. Thank you.

Super User

Hi @DataAnalystEvo try v2 below

Cumulative sum v2 =
VAR MaxDate =
MAX( ' Calendar'[Date] )
VAR CumulativeSum =
CALCULATE(
SUM( 'Table'[Amount ),

'Calendar'[Date] <= MaxDate,
ALL('Calendar')
)
)
RETURN CumulativeSum

Proud to be a Super User!