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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
525380
Frequent Visitor

How do I find keep a running total until it hits the max size or less. Otherwise it needs to restart

I calculate the Remainder:

 

Remainder =
VAR a =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Epic' ),
            [Epic ID] <= SELECTEDVALUE ( 'Epic'[Epic ID] )
        ),
        [TeamsPI Avg]
    )
VAR b =
    CALCULATE (
        SUM ( 'Epic'[Portfolio Supply] ),
        'Epic'[Epic ID] = SELECTEDVALUE ( 'Epic'[Epic ID] )
    )
RETURN
  MOD ( a, b )
 
And then get the running total : 
Running Total =
VAR a =
    COUNTROWS (
        FILTER (
            ALL ( 'Epic' ),
            [Epic ID] < SELECTEDVALUE ( 'Epic'[Epic ID] )
                && [Remainder] = 0
        )
    )
VAR b =
    CALCULATE (
        SUM ( 'Epic'[Portfolio Supply] ),
        'Epic'[Epic ID] = SELECTEDVALUE ( 'Epic'[Epic ID] )
    )
RETURN
    SUMX (
        FILTER ( ALL ( 'Epic' ), [Epic ID] <= SELECTEDVALUE ( 'Epic'[Epic ID] ) ),
        [TeamsPI Avg]
    ) - b * a
 
When the Running Total hits 30 a line is printed out:
PI =
VAR a =
    CALCULATE (
        SUM ( 'Epic'[Portfolio Supply] ),
        'Epic'[Epic ID] = SELECTEDVALUE ( 'Epic'[Epic ID] )
    )
RETURN
    "PI "
        & COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Epic' ),
                [Epic ID] < SELECTEDVALUE ( 'Epic'[Epic ID] )
                    && [Running Total] = a
            )
        ) + 1
 
This all works exept that it has to = 30(the max size). I want it to hit the max size or less, otherwise it starts the running total again and prints out new PI(period). 
525380_0-1682298630486.png

 

 
1 ACCEPTED SOLUTION

Hm, I'm unfortunately stumped at the moment after looking at it for a while. The closest I got was using a cumulative total and the quotient in the PI measure, which at least solves your issue running total not resetting if the remainder was non-zero. However, that doesn't quite work with your requirement that the running total resets.

 

PI = 
VAR CumulativeTotal =
CALCULATE (
    SUM ( Epic[TeamsPi Avg] ),
    REMOVEFILTERS ( Epic ),
    Epic[Epic ID] <= SELECTEDVALUE ( Epic[Epic ID] )
)
VAR Divisor = SELECTEDVALUE ( Epic[Portfolio Supply] )
VAR Suffix = IF ( Divisor <> 0, QUOTIENT ( CumulativeTotal - 1, Divisor ) )
VAR Result = "PI " & FORMAT ( Suffix + 1, "0" )

RETURN IF ( ISINSCOPE ( Epic[Epic ID] ), Result ) -- gets rid of the nonsensical Total value

 Accounting for the reset the first time it's with a non-zero remainder is easy; keeping that "memory" has proved more difficult for me, since you can only use one "formula" for the entire "column".

 

I wish I could be of more help at the moment but the above is the best I have for now. If I figure something else out, I'll let you know. 😄 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

6 REPLIES 6
Wilson_
Super User
Super User

Hello,

 

Can you please share your pbix file?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





How do i attach my PBIX to this post? I looked at all the buttons and don't see an attach file or pbix. I see attach media, link pic, etc., but none to upload the PBIX. 

You can upload it somewhere (ex: Google drive or Dropbox) and share the link to the file.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hm, I'm unfortunately stumped at the moment after looking at it for a while. The closest I got was using a cumulative total and the quotient in the PI measure, which at least solves your issue running total not resetting if the remainder was non-zero. However, that doesn't quite work with your requirement that the running total resets.

 

PI = 
VAR CumulativeTotal =
CALCULATE (
    SUM ( Epic[TeamsPi Avg] ),
    REMOVEFILTERS ( Epic ),
    Epic[Epic ID] <= SELECTEDVALUE ( Epic[Epic ID] )
)
VAR Divisor = SELECTEDVALUE ( Epic[Portfolio Supply] )
VAR Suffix = IF ( Divisor <> 0, QUOTIENT ( CumulativeTotal - 1, Divisor ) )
VAR Result = "PI " & FORMAT ( Suffix + 1, "0" )

RETURN IF ( ISINSCOPE ( Epic[Epic ID] ), Result ) -- gets rid of the nonsensical Total value

 Accounting for the reset the first time it's with a non-zero remainder is easy; keeping that "memory" has proved more difficult for me, since you can only use one "formula" for the entire "column".

 

I wish I could be of more help at the moment but the above is the best I have for now. If I figure something else out, I'll let you know. 😄 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





I appreciate you trying! If you can think of anything let me know. I'm still thinking and maybe need to redo the logic altogether. 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.