Forum Discussion
Get the median based on certain column
Hello im trying to compute median of the market value (MV) for each of site based on municipality which the site is located, and if there is no record of MV for the particular municipality, get the median based on the province which the site is located.
I have 3 tables:
| LGU List | ||
| Province | Municipality | LGU Code |
| SID | |
| Site ID | LGU Code |
| Consolidated TD List | |||
| Site ID | TD No | Property Type | MV |
LGU list has one to many relationship with SID using LGU Code, wile SID has one to many relationship with Consolidated TD List using site ID.
I tried to come up with a measure like this:
Median Measure =
VAR MedMun=
CALCULATE(
MEDIAN('Consolidated TD List'[MV]),
'Consolidated TD List'[TDNo] <> BLANK(),
CONTAINSSTRING('Consolidated TD List'[Property Type], "Building"),
REMOVEFILTERS('LGU List'[LGU Code]),
VALUES('LGU List'[Municipality])
)
VAR MedProv =
CALCULATE(
MEDIAN('Consolidated TD List'[MV]),
'Consolidated TD List'[TDNo] <> BLANK(),
CONTAINSSTRING('Consolidated TD List'[Property Type], "Building"),
REMOVEFILTERS('LGU List'[LGU Code]),
VALUES('LGU List'[Province])
)
RETURN
IF(
MedMun>0,
MedMun,
MedProv
)
Somehow it is not working. My visual is a simple one, list of site ids and the median, with grandtotal. Let me know what needs to change. Thanks
Median = COALESCE(medianx(TDList,TDList[MV]),CALCULATE(medianx(TDList,TDList[MV]),REMOVEFILTERS(LGUlist[Municipality])))- Anonymous4 years ago
ok thanks will check the measure will get back to you if i encounter any issues. anyway many thanks for your time
13 Replies
- lbendlin
Super User
Please provide sanitized sample data that fully covers your issue. I cannot help you without usable sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. I cannot use screenshots of your source data.
Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523- AnonymousNot applicable
Hello Ibendlin,
I manage to create a sample pbix file so you can check, my goal is create another measure to get the median of the mv per site per municipality (if not available per province). me initially thinking using mediax but that will entail me coming up two mediax for each site (one per municipality and one per province). another thing, there are unmatched site ids between td list and sid, my work around was to create a calculated column in the td list. Can you suggest another way to only count those matched site ids?
https://drive.google.com/drive/folders/1f0ew6RAl4s26fKzJFnNvy9CHaweTRpQR?usp=sharing
- lbendlin
Super User
I don't see what's wrong with your median calculation. Seems to work as designed?