Forum Discussion
Add percentiles using a calculated measure
Hello everyone, first time posting, I will do my best to make this post right :
I am stuck right now on a rather complex report I was asked to maintain and update.
The way the data model is made, we have one main table with many subcategories (employment, Births,Deaths etc...), aggregated to the city.
In this report, I have a calculated measure that finds the Ratio of employment by country by divising the sum of employees by the sum total of people in all the cities within the country.
Once this measure is calculated, I was asked to create the percentile measure to know how each country relate in term of employibility between each other.
Problem, the pre-built functions in power bi all use data that come from a column, and all I have is a calculated measure.
I tried several different solutions, but I never managed to get to the result.
Little bonus challenge : I have to create the percentile of each of those, for countries and cities using a ratio made with the categories I mentioned.
If what I said is not clear enough, I can try to make a make up simplified file.
Thank you for reading my mail,
Dimitri
10 Replies
- AnonymousNot applicable
"Problem, the pre-built functions in power bi all use data that come from a column, and all I have is a calculated measure."
That's not true, of course. All functions that end in X (SUMX, AVERAGEX...) can calculate the required value using measures. They do iterate over some kind of a value in some kind of a column but this is totally normal and even desired since measures are always calculated against some member(s) in some column(s).
- AnonymousNot applicable
Hello,
Sorry for the confusion, what I meant to say is that the 4 percentile functions use either a column from a table, or a table itself.
Since I am using a calculated measure to base my percentile on, I have troubles creating my calculated measure.
I have made a simpler version of the file that I can share here.
I would like to be able to calculate the percentile for both the country and the city , but for now I thought about focusing on the country alone.
(for some reasons I cannot link a PBIX file, so for now I will send screen shots)
ā
- AnonymousNot applicable
What's wrong with PERCENTILEX.INC - DAX Guide?
By the way, it's still not clear what you mean by a "percentile measure." A percentile is a 2-variable function , f(x: Multiset(R), y: R) -> R , that depends on: (x) the data set you give it and (y) the threshold you define between 0 and 1. So I'm still unable to determine exactly what you really want. Which exactly percentile are you talking about? For instance, if you want the 25th percentile (the 1st quartile) for cities based on some [M]easure calculated for the cities, then you'd write:
percentilex.inc( summarize( FactTable, Cities[CityID] ), [M], 0.25 )If you want the same but just for countries, then you'd need to change Cities[CityID] to some kind of Country[CountryID]. If you want to have percentiles for different levels of a hierarchy, then you'll have to create a specific measure for this very hierarchy using ISINSCOPE and a proper formula for each level...
- AnonymousNot applicable
What I am trying to do is to have in which percentile all those cities are. For example, if they are in the top 90% it would be 0.9.