cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
johnsonrs Frequent Visitor
Frequent Visitor

Calculation of Moving Average depending on the date and other value in the same row

Hey everyone, 

 

I already red quite a bit in the community but I did not find the proper solution to my problem.

 

I have a table with following columns

 

SKU, DATE, STOCKLEVEL, SALES

 

With contains data on a daily level for different SKU.

 

Now I want to calculate the Average Sales based on the date and the SKU in ONE row and save that in a new column. I what to that to as a column because I what to be able to filter over it afterwards.

SKU, DATE, STOCKLEVEL, SALES, NEWCOLUMN

A - 01.01.2017- 100 - 10 - Average Sales for the Product A in the last 30 days before the 01.01.2017

 

I also have an seperate date table and a table containing the sales per SKU, and date if this might help.

 

Thanks in advance!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft v-jiascu-msft
Microsoft

Re: Calculation of Moving Average depending on the date and other value in the same row

Hi @johnsonrs,

 

You could try this formula. 

AverageCol =
CALCULATE (
    AVERAGE ( TableA[SALES] ),
    DATESINPERIOD ( 'Calendar'[Date], 'TableA'[DATE], -30, DAY ),
    ALLEXCEPT ( TableA, TableA[SKU] )
)

One note: If the data is 2017-01-01  100, 2017-01-30  200, the average is (100 + 200) / 2 = 150. NOT (100 + 200) / 30 = 10.

 Calculation of Moving Average depending on the date and other value in the same row.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

Community Support Team _ Dale
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
Microsoft v-jiascu-msft
Microsoft

Re: Calculation of Moving Average depending on the date and other value in the same row

Hi @johnsonrs,

 

You could try this formula. 

AverageCol =
CALCULATE (
    AVERAGE ( TableA[SALES] ),
    DATESINPERIOD ( 'Calendar'[Date], 'TableA'[DATE], -30, DAY ),
    ALLEXCEPT ( TableA, TableA[SKU] )
)

One note: If the data is 2017-01-01  100, 2017-01-30  200, the average is (100 + 200) / 2 = 150. NOT (100 + 200) / 30 = 10.

 Calculation of Moving Average depending on the date and other value in the same row.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

Community Support Team _ Dale
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

aar0n Member
Member

Re: Calculation of Moving Average depending on the date and other value in the same row

I am hoping to do a very similar situation - you have it for a 30 day time frame, but the only difference is that i need it to take the average of every value - up to that row!

 

Any suggestions?

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors