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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
renmello
Helper I
Helper I

Trend of a moving average

Hello, everyone. 

I was practing my skills with covid data from Brazil and i am stuck calculating the trend of the moving average of 10 days from new cases.

I have this table with the date, the new cases each day and the moving average of 10 days for the day.Media Movel 1.JPG
What i would like to do is to select the moving average from lastdate and divide by only the moving average of 10 days ago.

Media Movel 2.JPG

I am able to select only the moving average of lastdate, but when i try to only select the moving average of 10 days ago it returns the last moving average. 

Anyone have any ideas? 

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @renmello ,

 

Please try the following.

 

I did it with a 3 days average and build 3 measures (average, average from 3 days ago and comparison)

 

3 day average = CALCULATE(AVERAGE(fact_table_d[Sales]),DATESBETWEEN('Date'[Date],MAX('Date'[Date])-2,MAX('Date'[Date])))
 
get measure value from 3 days ago = CALCULATE([3 day average],DATEADD('Date'[Date],-3,DAY))
 
Compare both measures = [3 day average] / [get measure value from 3 days ago]
 
Please find below the results.
 
Picture 1.PNG

 

Hope this helps.

 

Best regards

Mikelytics

 

Did I solve your request? Please mark my post as solution.

 

Appreciate your Kudos.

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

2 REPLIES 2
renmello
Helper I
Helper I

Hello, thanks for the reply!

It worked perfectly. Dateadd is what i was missing to select the moving average from 14 days ago. Thanks for the help 🙂 

Mikelytics
Resident Rockstar
Resident Rockstar

Hi @renmello ,

 

Please try the following.

 

I did it with a 3 days average and build 3 measures (average, average from 3 days ago and comparison)

 

3 day average = CALCULATE(AVERAGE(fact_table_d[Sales]),DATESBETWEEN('Date'[Date],MAX('Date'[Date])-2,MAX('Date'[Date])))
 
get measure value from 3 days ago = CALCULATE([3 day average],DATEADD('Date'[Date],-3,DAY))
 
Compare both measures = [3 day average] / [get measure value from 3 days ago]
 
Please find below the results.
 
Picture 1.PNG

 

Hope this helps.

 

Best regards

Mikelytics

 

Did I solve your request? Please mark my post as solution.

 

Appreciate your Kudos.

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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