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
niel_orvyn1
Helper III
Helper III

Rolling average per minute

Rolling average per second and minute

 

I need help on a moving average per second and minute. I’ve surfed the web for many days now, I’ve tried most of the posted solutions but I cannot seem to crack it.

 

I’m trying to determine a moving average for events [TPS] per time stamp, in this case the rolling average looking at seconds in a minute. Once I have total events per second, I would like to calculate the rolling average per minute.

 

I’ve created a new table with ‘DateTimeTable’  so I could have a calendar with all-time stamps for a period (this case 3 months), and used a left outer join to join it with the table ‘TokenMA60’ containing the data. The [ifisblank] looks if an event 'TokenMA

' occured and if not returns a zero or if, a value of 1. I tried using a below or over fuction that can be done with SQL. 

 

Below I have an excel example of what I would like to achieve, rather easy with a pivot:

Example Excel.png

 

Below the data in Power Bi (desktop)

PBI RollAVG Screenshot.png

 

Has anyone ever achieved this in with DaX/PowerBi? 

 

Regards

1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @niel_orvyn1 ,

 

We can use the following steps to meet your requirement.

 

1. We need to create a new calculate column to get the every minute.

 

Datetime 1 = FORMAT('Table'[Datetime],"YYYY/mm/dd hh:mm:00")

 

Rolling 1.jpg

 

2. Then create a measure. You can replace the SUM with AVERAGE.

 

Measure = CALCULATE(SUM('Table'[ifisblank]),FILTER(ALLSELECTED('Table'),'Table'[Datetime]<=MAX('Table'[Datetime])))

 

And create a table, put the [Datetime 1] and [Measure] in it. The result like this, 

 

Rolling 2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

5 REPLIES 5
v-zhenbw-msft
Community Support
Community Support

Hi @niel_orvyn1 ,

 

We can use the following steps to meet your requirement.

 

1. We need to create a new calculate column to get the every minute.

 

Datetime 1 = FORMAT('Table'[Datetime],"YYYY/mm/dd hh:mm:00")

 

Rolling 1.jpg

 

2. Then create a measure. You can replace the SUM with AVERAGE.

 

Measure = CALCULATE(SUM('Table'[ifisblank]),FILTER(ALLSELECTED('Table'),'Table'[Datetime]<=MAX('Table'[Datetime])))

 

And create a table, put the [Datetime 1] and [Measure] in it. The result like this, 

 

Rolling 2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

@v-zhenbw-msft 

Apologies for back tracking:

 

When I use as per below  "2. Then create a measure. You can replace the SUM with AVERAGE."

It works perfectly the column with [Datetime], the one that contains seconds:

 

MeasureAVG = CALCULATE(AVERAGE('Table'[ifisblank]),FILTER(ALLSELECTED('Table'),'Table'[Datetime]<=MAX('Table'[Datetime])))
 
 

MEASUREAVG.png

However on the right hand column containing [Datetime 1], its appears to give the moving average per the [Datetime] column. For the moving average where I would like to calculate:

Moving average.png Hope  my question is making sense. 

 

Let me know if you can help. 

 

Many thanks,

Niel

 

Hi

@v-zhenbw-msft  am very gratefull, I've spent days searching for the solution, I've googled almost every topic in this regard. 

If you have any links for ramp up of PowerBi skills please share. I've done DAT207x however, it only touches the surface of PowerBi, just my opinion and want to learn more. 

Best,

Niel

amitchandak
Super User
Super User

This Avg should reset every day or continue as is?

Hi 

The avg should continue and not reset everyday. The orig data is events over a 3 months period and I would like to see the average of events over the 3 months. 

Thanks in advance.

Regards,

Niel

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.