Forum Discussion

niel_orvyn1's avatar
niel_orvyn1
Helper III
6 years ago
Solved

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:

 

Below the data in Power Bi (desktop)

 

Has anyone ever achieved this in with DaX/PowerBi? 

 

Regards

  • 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")

     

     

    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, 

     

     

    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.

5 Replies

  • v-zhenbw-msft's avatar
    v-zhenbw-msft
    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")

     

     

    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, 

     

     

    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.

    • niel_orvyn1's avatar
      niel_orvyn1
      Helper III

      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

    • niel_orvyn1's avatar
      niel_orvyn1
      Helper III

      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])))
       
       

      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:

       Hope  my question is making sense. 

       

      Let me know if you can help. 

       

      Many thanks,

      Niel

       

    • niel_orvyn1's avatar
      niel_orvyn1
      Helper III

      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