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
chulpanvl
Helper I
Helper I

DAX: Monthly SMA on hourly data

Hello everyone!

 

I have a Table with number of visitors at some points in time. It is related to a Calendar table.

I need to plot a histogram with average monthly visitors and add a line with simple moving average sma(3) without aggregating the data first.

I managed to plot a histogram but failing at calculating SMA. A measure I’ve created doesn’t seem to work:

SMA =

    AVERAGEX(

    DATESINPERIOD('Table'[Date],LASTDATE('Table'[Date]), -3, MONTH),

    CALCULATE(AVERAGE('Table'[Sum by Day]))

)

Here is a pbix file to play with.

 

Hope to hear some advice here.

1 ACCEPTED SOLUTION

Hi @chulpanvl ,

 

By my tests,please refer to the sample pbix:

Vlianlmsft_0-1645498845408.png

 

 

Best Regards,
Liang
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

4 REPLIES 4
lbendlin
Super User
Super User

That's not really a histogram. But what's wrong with the SMA formula?  What would you have expected? How did you plan to handle all the days without visitors?

@lbendlin 

you’re right, I meant a column chart.

 

Initially I have hourly data. I’ve created a calculated column Sum by Day. Then there is a measure avg = AVERAGE('Table'[Sum by Day]), which returns average daily number of visitors per month if plotted as a column chart vs month on x-axis. Now I want to add SMA line to this chart, which is basically an average of an average, if it makes any sense. E.g., for the last 3 months the values for avg measure are 34.17, 53.67, 41.67. So I would expect of SMA to return 43.17 for March 2022. But SMA returns same values as avg measure. What am I doing wrong?

 

> How did you plan to handle all the days without visitors?

I assume there are no such days.

Hi @chulpanvl ,

 

By my tests,please refer to the sample pbix:

Vlianlmsft_0-1645498845408.png

 

 

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

Hi @V-lianl-msft, thank you for your solution!

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.