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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
AmazingRandom
Helper I
Helper I

Rolling month and end of month averages in calculated columns

I have been trying to aggregate daily volume data in to a rolling average and one end of month average, however, the source gives averages far higher than the daily volumes and any calculated columns/measures I have tried using are not working. For example:

TimestampDaily Volume ThresholdDaily VolumeDischarge FlowMonthlyAvg
3/10/2024 0:00150.0060.02 
2/10/2024 0:00150.64999999349999990.573333328 
1/10/2024 0:001500 
30/09/2024 0:0015000.319349997
29/09/2024 0:00150.2869999970.436666662 
28/09/2024 0:00150.0209999997899999980.059999999400000004 
27/09/2024 0:00150.444999995549999970.606666661 
26/09/2024 0:001500 
25/09/2024 0:001500 
24/09/2024 0:00150.3309999970.829999992 
23/09/2024 0:00150.1059999990.216666665 
22/09/2024 0:00150.0269999997299999980.083333333 
21/09/2024 0:00151.012999990.729999993 
20/09/2024 0:00150.2879999970.463333329 
19/09/2024 0:00150.9419999910.569999994 
18/09/2024 0:00150.171999998279999980.253333331 
17/09/2024 0:00150.208999997909999980.643333327 
16/09/2024 0:00150.55799999442000010.926666657 
15/09/2024 0:00150.5039999950.876666658 
14/09/2024 0:00150.0379999996199999950.126666665 
13/09/2024 0:00150.3269999970.506666662 
12/09/2024 0:00150.167999998319999980.263333331 
11/09/2024 0:00150.0050.016666667 
10/09/2024 0:00150.5469999950.786666659 
9/09/2024 0:00150.0629999990.106666666 
8/09/2024 0:001500 
7/09/2024 0:00150.8149999920.796666659 
6/09/2024 0:00150.95399999046000010.689999993 
5/09/2024 0:00150.5389999950.899999991 
4/09/2024 0:00150.1919999980.639999994 
3/09/2024 0:00150.0430.089999999 
2/09/2024 0:00152.2969999770299991.033333323 
1/09/2024 0:00150.3849999961.02999999 

 

I ran this in excel so the average is supposed to be the 0.32 yet in the PBI calculated column it is saying 2.07 while in some other months it is even worse as it amount to the thousands when most daily values barely reach above 2. The calculated column is as follow, measure is pretty similar:

 

MonthlyAvg = 
IF(
    'Combined Trace Tables'[IsMonthEnd] = 1,
    CALCULATE(
        AVERAGE('Combined Trace Tables'[daily_volume]),
        FILTER(
            'Combined Trace Tables',
            YEAR('Combined Trace Tables'[Timestamp]) = YEAR(EARLIER('Combined Trace Tables'[Timestamp])) &&
            MONTH('Combined Trace Tables'[Timestamp]) = MONTH(EARLIER('Combined Trace Tables'[Timestamp]))
        )
    ),
    BLANK()
)

 

 

I am stryggling to edit and make this work, so I am open to any ideas.

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@AmazingRandom 

 

This sounds like a context issue. If you're creating a Calculated Column to compute average, and then use that in a visual, Power BI will store one value for every row in the column, and then will aggregate those values in the visual, so you're essentially going to end up with a SUM of Averages, if that makes any sense?

 

Do you have a dimDate table? https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

If so, you should be able to do a monthly average by using the Month of your date dimension, and AVERAGEX function ( https://www.dax.guide/averagex )

 

For example:

 

Monthly Average = 
AVERAGEX ( VALUES (dimDate[MonthYear] ), [Measure] )


From looking at your code, I think the [Measure] part of the expression above could be replaced with the SUM of your Daily Volume. NOTE: this will give you MONTHLY average, so yes, the numbers will be much higher than the daily volume, as it's adding them all up for the month.

 

If you just want a daily average for each month, then you can just use the below measure, and use your DimDate[MonthYear] column in the visual to group by Month:

 

Daily Average = 
AVERAGEX ( DimDate, [Measure] )

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
AllisonKennedy
Super User
Super User

@AmazingRandom 

 

This sounds like a context issue. If you're creating a Calculated Column to compute average, and then use that in a visual, Power BI will store one value for every row in the column, and then will aggregate those values in the visual, so you're essentially going to end up with a SUM of Averages, if that makes any sense?

 

Do you have a dimDate table? https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html

 

If so, you should be able to do a monthly average by using the Month of your date dimension, and AVERAGEX function ( https://www.dax.guide/averagex )

 

For example:

 

Monthly Average = 
AVERAGEX ( VALUES (dimDate[MonthYear] ), [Measure] )


From looking at your code, I think the [Measure] part of the expression above could be replaced with the SUM of your Daily Volume. NOTE: this will give you MONTHLY average, so yes, the numbers will be much higher than the daily volume, as it's adding them all up for the month.

 

If you just want a daily average for each month, then you can just use the below measure, and use your DimDate[MonthYear] column in the visual to group by Month:

 

Daily Average = 
AVERAGEX ( DimDate, [Measure] )

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Thank you! Using the dimdate helped solve it

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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