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
danca
New Member

Struggling to calculate an average of ages including zero

Hi everyone! I'm wondering if anyone here is able to guide me in the right direction regarding an issue I've been having. I am no expert in Power BI so I'm almost certain that this issue has an easy solution but I haven't been able to find it in these forums or elsewhere.

 

I have a database with data of different units within a hospital, and how many patients of different ages they see every month. In this database, each row if a different age at a different hospital unit on a different month, and then there is a column that expresses the number of patients of that age that were seen in the specific hospital unit on the specific month. I attach an example of the date, with all identifiers removed:

 

MonthUnitAgeNumber of patients
JanuaryHeart surgery02
JanuaryHeart surgery16
JanuaryHeart surgery24
JanuaryHeart surgery311
JanuaryHeart surgery49
JanuaryPsychiatric unit00
JanuaryPsychiatric unit10
JanuaryPsychiatric unit23
JanuaryPsychiatric unit38
JanuaryPsychiatric unit419
FebruaryPsychiatric unit00
FebruaryPsychiatric unit10
FebruaryPsychiatric unit21
FebruaryPsychiatric unit35
FebruaryPsychiatric unit414

 

 

What I'm trying to do is have a card in my Power BI report that shows the average age of all patients seen by the unit that the user chooses (through a slicer), on the month the user chooses. So in the example above, the average age of all patients seen by the Heart surgery unit in January should be 2.59.

 

No matter how hard I try, I can't get Power BI to produce the right average. I suspect that the problem is linked to the fact that one of the age groups is 0, and some age groups have a number of patients that is = 0, which seems to 'throw off' most average calculations. I've tried using measures in Power BI and also going over to Power Query to create columns that should calculate the average correctly, but in the end I just can't get the right average in my cards. What could I be missing here? How would you guys go about producing this average?

 

Thanks a lot in advance!

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User
5 REPLIES 5
Ahmedx
Super User
Super User

That did the trick. Thanks a lot for your help!

Ahmedx
Super User
Super User
Ahmedx
Super User
Super User

Can you explain how you calculate the average for Heart surgery unit in January? как у вас получилось 2,59

Total number of patients for Heart surgery in January: 2+6+4+11+9 = 32

Total age of all patients for Heart surgery in January: (0x2) + (1x6) + (2x4) + (3x11) + (4x9) = 83

Total age of all patients divided by total number of patients= 83/32 = 2.59375

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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