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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Filtered Running Total

Trying to create a prior 7 years Total in the Install Base row, so first year that should be displayed in this row would be 2015, and it would pull from Total Sold row for years 2008-2014.  Looking at image below, you can see in the Install Base row I am getting a total of 225,291, where I should really be getting 1,005,727 (Sum of years from 2008-2014 from Total Sold).  

Greatly appreciate any help on correcting my formula.Power Bi Help.jpg

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

You can try this:

previous 7 years total =
CALCULATE (
    [Total Sold],
    DATESINPERIOD (
        'Whole Goods'[Fiscal Date],
        LASTDATE ( 'Whole Goods'[Fiscal Date] ),
        -7,
        YEAR
    )
)
Install Base =
VAR mindate =
    CALCULATE (
        MIN ( 'Whole Goods'[Fiscal Date] ),
        ALLSELECTED ( 'Whole Goods'[Fiscal Date] )
    )
RETURN
    IF (
        YEAR ( MAX ( 'Whole Goods'[Fiscal Date] ) ) - 7
            < CALCULATE (
                YEAR ( FIRSTDATE ( 'Whole Goods'[Fiscal Date] ) ),
                ALL ( 'Whole Goods' )
            ),
        BLANK (),
        CALCULATE (
            [previous 7 years total],
            FILTER (
                ALL ( 'Whole Goods' ),
                DATEADD ( 'Whole Goods'[Fiscal Date], 1, YEAR )
                    <= MAX ( 'Whole Goods'[Fiscal Date] )
                    && DATEADD ( 'Whole Goods'[Fiscal Date], 1, YEAR ) >= mindate
            )
        )
    )

Filtered Running Total.PNG

This is my PBIX file.

 

Best Regards,

Icey

 

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

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

You can try this:

previous 7 years total =
CALCULATE (
    [Total Sold],
    DATESINPERIOD (
        'Whole Goods'[Fiscal Date],
        LASTDATE ( 'Whole Goods'[Fiscal Date] ),
        -7,
        YEAR
    )
)
Install Base =
VAR mindate =
    CALCULATE (
        MIN ( 'Whole Goods'[Fiscal Date] ),
        ALLSELECTED ( 'Whole Goods'[Fiscal Date] )
    )
RETURN
    IF (
        YEAR ( MAX ( 'Whole Goods'[Fiscal Date] ) ) - 7
            < CALCULATE (
                YEAR ( FIRSTDATE ( 'Whole Goods'[Fiscal Date] ) ),
                ALL ( 'Whole Goods' )
            ),
        BLANK (),
        CALCULATE (
            [previous 7 years total],
            FILTER (
                ALL ( 'Whole Goods' ),
                DATEADD ( 'Whole Goods'[Fiscal Date], 1, YEAR )
                    <= MAX ( 'Whole Goods'[Fiscal Date] )
                    && DATEADD ( 'Whole Goods'[Fiscal Date], 1, YEAR ) >= mindate
            )
        )
    )

Filtered Running Total.PNG

This is my PBIX file.

 

Best Regards,

Icey

 

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

 

Anonymous
Not applicable

This solution worked, thank you Icey!

parry2k
Super User
Super User

@Anonymous as best practice, it is good to have date dimension in your model and then run time based calculation from date dimension. There are many posts on how to add date to your data model. Once you have date dimension, you can use DATESBETWEEN function to achieve the goal.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thank you for the advice Perry 2k but I was still unable to get this to come back with the data I was looking for.  I am still new to Power Bi so I am sure it is user error, but the suggestion that Icey  supplied was able to get me the data that I needed.  Thank you again for your input.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.