cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

calculate average per category per year

hello,

 

New to power bi here and would appreciate some help. 

I want to calculate the average of units per year for apo key and material key (which make a distinct category) for my data. 

For certain purposes the average needs to be calculated for previous year, current year and next year which are denoted by 'PY', 'CY' and 'NY' in a column marked 'IS YEAR'. 

 

the column highlighted is what i need to obtain. 

 

I have tried using this- 

Avg =
CALCULATE (
AVERAGE (z[units] ),
FILTER (z, z[material key]=EARLIER(z[material key]))
)
which is calculating the average based on apo key and material key but the average does not change for different years.
 
can someone provide help with this.
Thanks 🙂sample.PNG
1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

You're nearly there.  You just have to add in the other conditions (which you have described) in to the filter.

e.g.  && z[apo key] = EARLIER (z[apo key])

 

and the same for year.

 

Edit: the CY, NY and PY are irrelevant because you have the Year pre-calculated . Can you confirm?

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

hey! 

the calculation of the average went well. but now i'm stuck at calculating standard deviation of units per category (apo key+ material key) per year which is PY,CY and NY

 

I understand simply using the stdev.p wouldnt work as it computes based on the formula SUM(X-Xavg)^2/n and  n keeps changing per category per year.

is using stdevx.p a better apporach? 

if so, then what would be the expression for it so that standard deviation is obtained per category per year?

 

thank you 🙂

HotChilli
Super User
Super User

You're nearly there.  You just have to add in the other conditions (which you have described) in to the filter.

e.g.  && z[apo key] = EARLIER (z[apo key])

 

and the same for year.

 

Edit: the CY, NY and PY are irrelevant because you have the Year pre-calculated . Can you confirm?

Anonymous
Not applicable

Yep that works 🙂 

i really dont understand how i missed this small step. 

Looks like i need to take a break.

But thanks a tonne

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!