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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Torbuzz
Frequent Visitor

Accumulative function and sum not working

Hi All,

Below is my data sample

Torbuzz_0-1709174228730.png

I want to have result like this 

Torbuzz_3-1709174570763.png

I use this formula that the accumulation didn't work

SisaStok =
Var TotInItem = SUM('Item'[In])
Var TotOutItem = SUM('Item'[Out])
Var TotAll = TotInItem - TotOutItem
Var Result = CALCULATE(IF(TotAll<0,0,TotAll),FILTER(ALLSELECTED(Kalender),Kalender[Date]<=MAX(Kalender[Date])))
RETURN
Result

 

Any support on this, highly appriciated.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Torbuzz ,

 

If you want to get result as your question, I think you need to sort your table by [Date] and [Name].

vrzhoumsft_0-1709285168687.png

Measure:

GrandTotal = CALCULATE(SUM('Table'[In]) - SUM('Table'[Out]))
SisaStok =
VAR _Step1 =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        'Table'[Index],
        Kalender[Year],
        Kalender[MonthSort],
        'Table'[Name],
        "GrandTotal", [GrandTotal],
        "Group",
            MAXX (
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    [GrandTotal] < 0
                        && 'Table'[Index] < EARLIER ( 'Table'[Index] )
                ),
                'Table'[Index]
            )
    )
VAR _Step2 =
    ADDCOLUMNS (
        _Step1,
        "RunningTotal",
            IF (
                [GrandTotal] < 0,
                0,
                SUMX (
                    FILTER (
                        _Step1,
                        [Group] = EARLIER ( [Group] )
                            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
                    ),
                    [GrandTotal]
                )
            )
    )
RETURN
    SUMX ( FILTER ( _Step2, [Index] IN VALUES ( 'Table'[Index] ) ), [RunningTotal] )

Result is as below.

vrzhoumsft_1-1709285211269.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Torbuzz
Frequent Visitor

Now I change the formula to be like this :

SisaStok =
Var Result = CALCULATE([GrandTotal],FILTER(ALLSELECTED(Kalender),Kalender[Date]<=MAX(Kalender[Date])))
RETURN
IF(Result<0,0,Result)
 
The result of the February speaker item is not 20 and the sum value should be 200
Torbuzz_0-1709193046415.png

What should I do? 

 
Anonymous
Not applicable

Hi @Torbuzz ,

 

If you want to get result as your question, I think you need to sort your table by [Date] and [Name].

vrzhoumsft_0-1709285168687.png

Measure:

GrandTotal = CALCULATE(SUM('Table'[In]) - SUM('Table'[Out]))
SisaStok =
VAR _Step1 =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        'Table'[Index],
        Kalender[Year],
        Kalender[MonthSort],
        'Table'[Name],
        "GrandTotal", [GrandTotal],
        "Group",
            MAXX (
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    [GrandTotal] < 0
                        && 'Table'[Index] < EARLIER ( 'Table'[Index] )
                ),
                'Table'[Index]
            )
    )
VAR _Step2 =
    ADDCOLUMNS (
        _Step1,
        "RunningTotal",
            IF (
                [GrandTotal] < 0,
                0,
                SUMX (
                    FILTER (
                        _Step1,
                        [Group] = EARLIER ( [Group] )
                            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
                    ),
                    [GrandTotal]
                )
            )
    )
RETURN
    SUMX ( FILTER ( _Step2, [Index] IN VALUES ( 'Table'[Index] ) ), [RunningTotal] )

Result is as below.

vrzhoumsft_1-1709285211269.png

 

Best Regards,
Rico Zhou

 

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

 

Hi @Anonymous ,

Perfect, many thanks. 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.