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
D_PBI
Post Partisan
Post Partisan

Rolling Total not showing as needed - please help

Hi,
I need to create two measures as follows:
Measure 1) to show the rolling total up to the last (max) date as specified in the matrix.
Measure 2) to show the rolling total for all dates, whether selected in the matrix or not, up to the last (max) date as specified in the matrix.

The Date table (dimDate) has two relationships to the Agreement table (agreement) in the data model.
The active relationship is dimDate[Date] to agreement[Execution Date].
The inactive relationship is dimDate[Date] to agreement[Received Date].

The relevant code snippet is (but it isn't correct):

D_PBI_1-1747825240298.png


D_PBI_0-1747825202425.png


The [__Number of Distinct Agreements] is simply DISTINCTCOUNT( agreement[agreementid] ).

The output is to be shown in a Matrix visual as below (although the screenshot below doesn't have the correct figures - hence this post):

D_PBI_3-1747825658224.png


The above Matrix has the date heirarchy of Financial Year (FY), Financial Quarter (FQ), and Month Name (MN), all from the dimDate table. You'll note only the Financial Year is shown in the Matrix above. The measure needs to calculate for FY, FQ, and MN when they are expanded.

The agreement[Team Name] is across the columns in the Matrix.

By way of slicers, the report user will have the ability to selected/deselect FY, FQ, and MN, as well as Team Name, as well as other attributes.

The needed measures should show in the Matrix as follows:
Measure 1) - a rolling total for the numbers actually selected (and shown) in the matrix visual.
FY               Res
2024-25      64
2023-24      49
2022-23      35
2021-22      19

Measure 2) - peforming a rolling total for all years whether selected or not.
FY               Res
2024-25      2187
2023-24      2172
2022-23      2158
2021-22      2142
This is becuase prior to 2021-22 there was a total of 2123 agreementids. This is what I mean by this measure needs to perform a rolling total for all years whether selected or not.

Please can you help me achieve this?  Thanks.

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

You can try

Rolling Total Selected Dates =
VAR MaxDate =
    MAX ( __dimDate[Date] )
VAR Result =
    CALCULATE (
        [__Number of distinct Agreements],
        USERELATIONSHIP ( __dimDate[Date], agreement[Received Date] ),
        FILTER ( ALLSELECTED ( __dimDate[Date] ), __dimDate[Date] <= MaxDate )
    )
RETURN
    Result

and 

Rolling Total All Time =
VAR MaxDate =
    MAX ( __dimDate[Date] )
VAR Result =
    CALCULATE (
        [__Number of distinct Agreements],
        USERELATIONSHIP ( __dimDate[Date], agreement[Received Date] ),
        __dimDate[Date] <= MaxDate
    )
RETURN
    Result

View solution in original post

Change measure 1 to be

Rolling Total Selected Dates =
VAR MaxDate =
    MAX ( __dimDate[Date] )
VAR Result =
    CALCULATE (
        [__Number of distinct Agreements],
        USERELATIONSHIP ( __dimDate[Date], agreement[Received Date] ),
        FILTER ( ALLSELECTED ( __dimDate ), __dimDate[Date] <= MaxDate )
    )
RETURN
    Result

That is moving the ALLSELECTED from the column to the full table.

View solution in original post

4 REPLIES 4
D_PBI
Post Partisan
Post Partisan

@johnt75 - thank you.

D_PBI
Post Partisan
Post Partisan

@johnt75  - I think I was premature in marking it as the solution. Thanks for your help.
Both of your measures are returning the same result. The below screenshot is the resultset for both of your measures (I've filtered the Team Name to be just 'Res').

D_PBI_0-1747834670604.png

The above output is what I require for Measure 2. However, for Measure 1, I required the rolling total for only the years selected.  Below are the numbers for each individual FY.

D_PBI_2-1747834846862.png

 

So Measure 1 would be:
FY              Res
2024-25     64
2023-24     49
2022-23     35
2021-22     19
2009-10     0

It's only rolling totalling the years selected. Can you help please?  Thanks.

Change measure 1 to be

Rolling Total Selected Dates =
VAR MaxDate =
    MAX ( __dimDate[Date] )
VAR Result =
    CALCULATE (
        [__Number of distinct Agreements],
        USERELATIONSHIP ( __dimDate[Date], agreement[Received Date] ),
        FILTER ( ALLSELECTED ( __dimDate ), __dimDate[Date] <= MaxDate )
    )
RETURN
    Result

That is moving the ALLSELECTED from the column to the full table.

johnt75
Super User
Super User

You can try

Rolling Total Selected Dates =
VAR MaxDate =
    MAX ( __dimDate[Date] )
VAR Result =
    CALCULATE (
        [__Number of distinct Agreements],
        USERELATIONSHIP ( __dimDate[Date], agreement[Received Date] ),
        FILTER ( ALLSELECTED ( __dimDate[Date] ), __dimDate[Date] <= MaxDate )
    )
RETURN
    Result

and 

Rolling Total All Time =
VAR MaxDate =
    MAX ( __dimDate[Date] )
VAR Result =
    CALCULATE (
        [__Number of distinct Agreements],
        USERELATIONSHIP ( __dimDate[Date], agreement[Received Date] ),
        __dimDate[Date] <= MaxDate
    )
RETURN
    Result

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.

May 2025 Monthly Update

Fabric Community Update - May 2025

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