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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

How to aggregate table based on moving sum

Hi,

 

I have a table with daily entries in this format for multiple years:

 

Location              Product                  Quantity                      Date

Minneapolis        Apples                    200                             3/22/2020

Minneapolis        Oranges                 234                             3/22/2020

Duluth                 Apples                   145                              3/22/2020

Duluth                 Oranges                 118                             3/22/2020

Minneapolis        Apples                    104                             3/23/2020

...

 

I want to:

1. Calculate which period of 28 consecutive days yielded the maximum quantity for each Location x Product pairing (ie get a moving sum for every 28 day period specific to that location and product, and then find the maximum value of it for each pairing).

2. Run/get additional statistics on dates in the identified max period for each Location x Product (ie average quantity, median quantity, start date of period, etc.)

 

Example output:

 

Location           Product                  Max Period Start Date                  Max Period Average Daily Quantity

Minneapolis     Apples                    1/14/2019                                     155.3

Minneapolis     Oranges                  2/3/2018                                       130.1

...

 

I've been able to create a measure that gives me a moving sum for each Location x Product x Day, but I've been unable to translate that back into getting only the rows associated with the max yield period for each location and product. I think if I could get the moving sum as a calculated column I could probably summarize my table based on that, but I'm stuck with it as a measure for now.

 

I also have pseudo data I can share if that would be helpful

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please correct me if I wrongly understood your question.

Please check the below picture if that is what you are looking for.

The link to the sample pbix file is down below, and all measures are in the file.

 

Picture1.png

 

https://www.dropbox.com/s/t2ypgefpqu2otdi/dancrist.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please correct me if I wrongly understood your question.

Please check the below picture if that is what you are looking for.

The link to the sample pbix file is down below, and all measures are in the file.

 

Picture1.png

 

https://www.dropbox.com/s/t2ypgefpqu2otdi/dancrist.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Yes. This helps a lot, thank you!

 

I think 'Start Date' is selecting the date preceding the max period instead of the first date in the period, but that's a simple fix if I add 1 to the return (ie 

enddates - nperiods + 1). I think I should be able to sort the rest of this out, thanks.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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