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:
|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
Solved! Go to Solution.
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.
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?
Hello, it is getting the median of the tds and not the sum of tds per site. I suppose medianx(sid, calculate(sum(tdlist[Mv]) can address that however as you can see in the result of your powerbi file. it has no value for city of legaspi, oas and jovellar. the values for these municipality wll be using the median for the entire albay province instead. the thing is if we can optimize the measure i do not have to use the medianx twice? (i.e. per municipality and per province) is there a way to create a variable table showing the values per site then use median instead of medianx?
Looks like I still don't understand what you are trying to achieve, and why. Are you maybe looking for the average instead of the median?
As you can see in the pbix file i sent to you, each site contains 2 or more TDs with different market values. I need to get the sum of all these tds for each site to get the market value per site. then for all the sites located in the specific municipality, get the median (not the average since i want to remove all possible outlier values that will distort the average value).
Please see the above screenshot, value of median is different if it simply based on the tds rather than the sum of the tds per site. As mentioned again, i know i can do medianx to achieve the result, however there are certain municipalities which do not have tds hence i can't get the median for that particular municipality. As remedy, i will need to get the median for the entire province. if that is the case that will mean i will also need to do medianx on per province. so my goal is to have an optimal measure that will allow me to get the median per lgu, if available, or else get the median per province. I hope this clears up my query.
sorry for the late reply, i will need to get the median per site for the entire municipality except those without mv such as jovelar, oas, and city of legaspi in which i will need to get the median per site for the entire province. Hope this clears things up. thanks
Hello please screenshot below.
For Camalig, since it has 3 sites with MV, the median measure should get 2319620 (the median per site for that particular municipality). Meanwhile, for city of legaspi, since it does not have sites with MV, the measure should get all the individual MV for each site for the entire province of albay then get the median.
made some minor modification but thanks for the help
Median Value = VAR PerMuni = CALCULATE( MEDIANX( SID, [MV Value] ), REMOVEFILTERS(SID[SiteID]) ) VAR PerProv = CALCULATE( MEDIANX( SID, [MV Value] ), REMOVEFILTERS(SID[SiteID]), REMOVEFILTERS(LGUlist[Municipality]) ) Return COALESCE(PerMuni,PerProv)*[No of Sites]
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.