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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Calculate and Store Rolling Total in DAX

Hello all,

 

I'm trying to calculate a rolling sum over a 5 day time period and store that sum for each date in my table. I've created a sample data set that shows the relevant calculations in excel. I have tried to implement a rolling total using multiple online sources, but nothing seems to work. I have successfully created the 'All Lots [lbs]' column to total the smaller values, but cannot figure out the rolling sum. Due to other calculation constraints, I must do this calculation with DAX, not PowerQuery M. I would greatly appreciate any help!

 

(*) is used here as a placeholder, nothing more.

holliebollie_0-1664211409755.png

 

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

I have created a simple sample, please refer to it to see if it helps you.

Create 2 columns.

 

all lots = 'Table'[Lot 1]+'Table'[Lot 2]+'Table'[Lot 3]

 

5 day rolling total =
VAR _5day = 'Table'[date] + 4
RETURN
    CALCULATE (
        SUM ( 'Table'[all lots] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] <= _5day
                && 'Table'[date] >= EARLIER ( 'Table'[date] )
        )
    )

vpollymsft_0-1664249342202.png

Best Regards

Community Support Team _ Polly

 

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

2 REPLIES 2
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

I have created a simple sample, please refer to it to see if it helps you.

Create 2 columns.

 

all lots = 'Table'[Lot 1]+'Table'[Lot 2]+'Table'[Lot 3]

 

5 day rolling total =
VAR _5day = 'Table'[date] + 4
RETURN
    CALCULATE (
        SUM ( 'Table'[all lots] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] <= _5day
                && 'Table'[date] >= EARLIER ( 'Table'[date] )
        )
    )

vpollymsft_0-1664249342202.png

Best Regards

Community Support Team _ Polly

 

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

Anonymous
Not applicable

Works like a charm, thank you for your help!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors