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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

A new measure that calculates rolling average by Cost Center

I have the following table:

OmiElhay_0-1674834092270.png

I want to calculate the monthly rolling average for Column Direct by CC. So for example the result should be as follows if month January and Feb are selected:

OmiElhay_1-1674834182781.png

What I did to get this result is first created a new table with the following formula:

OmiElhay_2-1674834231082.png

Which resulted in:

OmiElhay_3-1674834279444.png

Then I created a new measure in this new table with the following formula:

OmiElhay_4-1674834308588.png

I am now trying to get the same results using a measure in the original table. Without having to create the new summarized table.

 

Thanks,

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

Hi , @Anonymous 

According to your description, you want to "A new measure that calculates rolling average by Cost Center".

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)I create a date table like this:

Date = ADDCOLUMNS( CALENDAR( FIRSTDATE('Table'[Date]) ,LASTDATE('Table'[Date])) , "Year_month" , YEAR([Date])*100+MONTH([Date]))

vyueyunzhmsft_0-1675048327858.png

(2)We can create two measures :

Direct Sum = SUMX('Table','Table'[Direct])
Direct Rolling Average = var _t =ADDCOLUMNS(CROSSJOIN( VALUES('Table'[CC]) ,VALUES('Date'[Year_month])) , "direct" , CALCULATE(SUM('Table'[Direct])))
return
AVERAGEX(_t , [direct])

(3)Then we can put the fields we need on the visual and we can meet your need:

vyueyunzhmsft_1-1675048380374.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

For calculating the Rolling average, why have you taken the denominator as 2 for each CC?  Also, this is just a simple average.  Why do you call it a rolling average?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yueyunzh-msft
Community Support
Community Support

Hi , @Anonymous 

According to your description, you want to "A new measure that calculates rolling average by Cost Center".

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)I create a date table like this:

Date = ADDCOLUMNS( CALENDAR( FIRSTDATE('Table'[Date]) ,LASTDATE('Table'[Date])) , "Year_month" , YEAR([Date])*100+MONTH([Date]))

vyueyunzhmsft_0-1675048327858.png

(2)We can create two measures :

Direct Sum = SUMX('Table','Table'[Direct])
Direct Rolling Average = var _t =ADDCOLUMNS(CROSSJOIN( VALUES('Table'[CC]) ,VALUES('Date'[Year_month])) , "direct" , CALCULATE(SUM('Table'[Direct])))
return
AVERAGEX(_t , [direct])

(3)Then we can put the fields we need on the visual and we can meet your need:

vyueyunzhmsft_1-1675048380374.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Padycosmos
Solution Sage
Solution Sage

Perhaps this might help:

Rolling Average by CC =
CALCULATE(
AVERAGE(data[Column Direct]),
FILTER(
ALL(data),
data[month] >= MAX(data[month]) - 1
),
GROUPBY(data, data[CC], "Rolling Average by CC")
)

IoannisPhilip
Advocate II
Advocate II

Hi @Anonymous ,

maybe sth like the following can be useful:

Monthly_Rolling_Avg =
VAR sum_period = CALCULATE(SUM(table[DirectSum]), DATESINPERIOD(Table[Date]), LASTDATE[Table[Date]), 1, MONTH))
VAR month_in_period = CALCULATE(DISTINCTCOUNT(Table[Date]), DATESINPERIOD[Table[Date], LASTDATE(Table[Date]), 1, MONTH))
RETURN
sum_period / month_in_period

Alternatively, the kind of new function WINDOW(), might be handy.
I guess there are more efficient ways, but hopefully, this is working for you.

Anonymous
Not applicable

Thanks for your reply. But the formula doesn't summarize by cost center as well.

Greg_Deckler
Super User
Super User

@Anonymous See if this helps: Better Rolling Average - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks for sharing @gre2

the formula doesn't summarize by cost center as well. Which is the main struggle for me.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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