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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
LickNewin
Regular Visitor

Dividing the Subtotal without changing Values in Matrix

I'm trying to create a Power BI Measure that calculates an Average based on the amount of years (We use a relative date for the past 5 years, so the average should just be the sum of the row, divided by 5). I've tried to write the below Measure which adds the Average as a column but it's not calculating it correctly.

 

LickNewin_2-1714640385439.png

 

 

This is what it should look like - notice that the Average should be the total of each Age Bracket, divided by 5 for the amount of years.

As an example, for the '18-25' Age Bracket, the Sum total is 11, and when divided by 5, should give an average of 2.20 over 5 years.

Age Bracket20202021202220232024Average
Junior001000.20
18-25223402.20
26-30223001.40
31-35002301.00
36-40001200.60
41-45011000.40
46-50012501.60
51-55012000.60
56-60113101.20
61-65034001.40
66-70162502.80
71-75254403.00
76-802511504.60
81-850651104.40
86-90236603.40
91-95001200.60
96-99010000.20
100+100000.20

 

1 ACCEPTED SOLUTION

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1714705804348.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1714705804348.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey Ashish,

Thanks so much! Those values seem to work on your provided file, but I can't seem to replicate it. How did you accomplish this?

I've created the Table named Calendar and added the 'Year' calculation, as well as changing the Measure code, but mine comes out like this:

LickNewin_0-1714706804901.png

 

You are welcome.  Create a relationship (Many to One and Single) from the Resignation date column to the Date column of the Calendar table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

You're a legend! I've been stuck on this for 2 days.

That looks to be working now 🙂

You are welcome.  Thank you for your kind words.


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

Hi @LickNewin 

 

Please try the following DAX:

Average Over 5 Years = 
SUMX(
    VALUES('JoinedDate1'[Age Bracket]), 
    CALCULATE(SUM('JoinedDate1'[Member Number])) / 5
)

 

 

 

 

Best Regards,

Jayleny

 

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

Hey Jayleny, 

Unfortunately this doesn't work as the Column 'Age Bracket' is a String, not a number.

Some of the age brackets are "Junior" or "100+" so include characters other than numbers.

 

Please see the example PBIX attached here:

Working Average Function.pbix

LickNewin
Regular Visitor

It's a little hard to see, but the current measure that isn't working is:

 

Measure =
AVERAGEX(VALUES(JoinedData1[Resignation Year]), CALCULATE(COUNT(JoinedData1[Member Number])))

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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