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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hpatel24779
Helper II
Helper II

calculate median based on team

Hi,

I have a table consisting of Person ID, Team, Wait_weeks.

 

Person IDTeamWait_weeks
1A1
2A2
3A2
4A3
5B1
6B2
7C4
8C1
9C9
10D1
11D3
12D5
13D8
14D4
15E5
16E2
17E6
18E9

 

i want to create a measure that calculates the median wait_weeks if the team matches criteria.

 

for example, i want to find the median where team is A or D, median if team is C or E. Then i want to create a summary table as below:

TeamMedian by TeamMedian by Group
A23
B1.51.5
C45
D43
E5.55

 

I can get median by team but need help with the dax measure for median by group.

 

can anyone help me.

 

kind regards

 

Hetal

1 ACCEPTED SOLUTION
SamWiseOwl
Super User
Super User

Hi @hpatel24779 
The code will look something like this:

Median by group =
SWITCH(
    TRUE()
    ,SELECTEDVALUE('median table'[Team]) IN {"A","D"}, CALCULATE(MEDIAN('median table'[Wait_weeks]), 'median table'[Team] IN {"A","D"})
    ,SELECTEDVALUE('median table'[Team]) IN {"C","E"}, CALCULATE(MEDIAN('median table'[Wait_weeks]), 'median table'[Team] IN {"C","E"})
    ,MEDIAN('median table'[Wait_weeks])
)
 
For B I had it return just B's Median:
SamWiseOwl_0-1728913159510.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

3 REPLIES 3
hpatel24779
Helper II
Helper II

Thank you @Kedar_Pande  and @SamWiseOwl. tested your solutions and does exactly what i needed it to do.

 

much appreciated

Kedar_Pande
Super User
Super User

Measure

Median_by_Team = 
MEDIANX(
VALUES('YourTable'[Person ID]),
'YourTable'[Wait_weeks]
)

Measure for Median by Group:

Median_by_Group = 
SWITCH(
TRUE(),
'YourTable'[Team] IN {"A", "D"},
MEDIANX(
FILTER(
'YourTable',
'YourTable'[Team] IN {"A", "D"}
),
'YourTable'[Wait_weeks]
),
'YourTable'[Team] IN {"C", "E"},
MEDIANX(
FILTER(
'YourTable',
'YourTable'[Team] IN {"C", "E"}
),
'YourTable'[Wait_weeks]
),
BLANK() // Default case if no criteria match
)

Add a Table Visual in Power BI.
Include the Team column from your original table.
Add the measures Median_by_Team and Median_by_Group to the values area of the table.

 

If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

SamWiseOwl
Super User
Super User

Hi @hpatel24779 
The code will look something like this:

Median by group =
SWITCH(
    TRUE()
    ,SELECTEDVALUE('median table'[Team]) IN {"A","D"}, CALCULATE(MEDIAN('median table'[Wait_weeks]), 'median table'[Team] IN {"A","D"})
    ,SELECTEDVALUE('median table'[Team]) IN {"C","E"}, CALCULATE(MEDIAN('median table'[Wait_weeks]), 'median table'[Team] IN {"C","E"})
    ,MEDIAN('median table'[Wait_weeks])
)
 
For B I had it return just B's Median:
SamWiseOwl_0-1728913159510.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.