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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
525380
Frequent Visitor

How do I create a column that adds a rolling total until it hits a specific max value?

I would greatly be appreciative if someone could help.

 

I want to create a stacked graph that adds the value (team#) until it hits a specific maximum team# that I've specified in a different column. Each time it is adding the rolling total it will say Period 1, when it hits the max, it will then start the total again until it hits the max and will say Period 2. this happens until the max team # has been hit. 

 

This is the initial data:

Item IDItem SizeMax Size per Period
11030
22030
31030
4530
51530
61030
716 

 

I need in DAX formula to calculate Running Total of Item Size and Period Name so I can add to the bar graph and show the distribution like this. 

 

 Item IDItem SizeRunning Total of Item SizePeriod NameMaxSize per Period
 11010Period 130
 22030Period 130
 31010Period 230
 4515Period 230
 51530Period 230
 61010Period 330
 71626Period 330

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @525380 

You can refer to the following measures

1.Create a mesaure to calculate the remainder of the sum

Remainder =
VAR a =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Item ID] <= SELECTEDVALUE ( 'Table'[Item ID] )
        ),
        [Item Size]
    )
VAR b =
    CALCULATE (
        SUM ( 'Table'[Max Size per Period] ),
        'Table'[Item ID] = SELECTEDVALUE ( 'Table'[Item ID] )
    )
RETURN
    MOD ( a, b )

2.Then create a measure to create the rolloing total based on the reminder measure

Running Total =
VAR a =
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            [Item ID] < SELECTEDVALUE ( 'Table'[Item ID] )
                && [Remainder] = 0
        )
    )
VAR b =
    CALCULATE (
        SUM ( 'Table'[Max Size per Period] ),
        'Table'[Item ID] = SELECTEDVALUE ( 'Table'[Item ID] )
    )
RETURN
    SUMX (
        FILTER ( ALL ( 'Table' ), [Item ID] <= SELECTEDVALUE ( 'Table'[Item ID] ) ),
        [Item Size]
    ) - b * a

3.Create a measure to display size period based on Running Total measure

Size Period =
VAR a =
    CALCULATE (
        SUM ( 'Table'[Max Size per Period] ),
        'Table'[Item ID] = SELECTEDVALUE ( 'Table'[Item ID] )
    )
RETURN
    "Period"
        & COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Table' ),
                [Item ID] < SELECTEDVALUE ( 'Table'[Item ID] )
                    && [Running Total] = a
            )
        ) + 1

Output

vxinruzhumsft_0-1681956167195.png

 

Best Regards!

Yolo Zhu

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
Anonymous
Not applicable

Hi @525380 

You can refer to the following measures

1.Create a mesaure to calculate the remainder of the sum

Remainder =
VAR a =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Item ID] <= SELECTEDVALUE ( 'Table'[Item ID] )
        ),
        [Item Size]
    )
VAR b =
    CALCULATE (
        SUM ( 'Table'[Max Size per Period] ),
        'Table'[Item ID] = SELECTEDVALUE ( 'Table'[Item ID] )
    )
RETURN
    MOD ( a, b )

2.Then create a measure to create the rolloing total based on the reminder measure

Running Total =
VAR a =
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            [Item ID] < SELECTEDVALUE ( 'Table'[Item ID] )
                && [Remainder] = 0
        )
    )
VAR b =
    CALCULATE (
        SUM ( 'Table'[Max Size per Period] ),
        'Table'[Item ID] = SELECTEDVALUE ( 'Table'[Item ID] )
    )
RETURN
    SUMX (
        FILTER ( ALL ( 'Table' ), [Item ID] <= SELECTEDVALUE ( 'Table'[Item ID] ) ),
        [Item Size]
    ) - b * a

3.Create a measure to display size period based on Running Total measure

Size Period =
VAR a =
    CALCULATE (
        SUM ( 'Table'[Max Size per Period] ),
        'Table'[Item ID] = SELECTEDVALUE ( 'Table'[Item ID] )
    )
RETURN
    "Period"
        & COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Table' ),
                [Item ID] < SELECTEDVALUE ( 'Table'[Item ID] )
                    && [Running Total] = a
            )
        ) + 1

Output

vxinruzhumsft_0-1681956167195.png

 

Best Regards!

Yolo Zhu

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

 

 

Everything works, but it has to =30. I want it to = max size or less, otherwise it needs to re-start the running total and increment the new period or PI. 

525380_0-1682298920532.png

 

How do I make it so the remainder is the max size or less, ELSE start the running total over at 0. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.