cancel
Showing results 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

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.

1 ACCEPTED SOLUTION
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] )
)
)
``````

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.

2 REPLIES 2
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] )
)
)
``````

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!

Announcements

#### 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.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

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