//I have a list of students List<Student>
Students
{
lond StudentId;
double Marks;
int Rank;
double Percentile;
}
I am supplied with Id and Marks, and need to calculate rank and percentile.
I searched on methods for calculating percentile but they provide answer in different format like - how to calculate 95th percentile or 5th percentile.
But what i need to calculate is rank and specially percentile for every student and not a specific percentile holder.
thnx in advance...
Okay, so you need to first rank/sort all the Students by Mark such that the best grade is the first in the list. Then you can populate the Rank obviously by just counting up.
For the percentile you take (TotalNumberOfStudents - Rank of Student) / (TotalNumberOfStudents - 1)
So in other words, if you are the top ranked student you are better than 100% of the other students and if you are ranked 50 out of a 100 students then you are better than 50% of the students.
Now one wrinkle is that if students can have the same exact grade then they need to not be counted in the Denominator of the formula since that represents the number of students worse than you.
Related
Hi everyone,
I have a sample data as shown in the screenshot above. There are 3 students with different ID : student 123, student 234, student 456. The profit column in the table is how much they earn in each trade.
Winning trade = profit > 0
Losing trade = profit < 0
Based on the definition above for the winning trade and losing trade, I want to calculate the average winning rate for all the students.
Student 123 - the winning rate is 50% (2 negative profit and 2 positive profit)
Student 234 - the winning rate is 33.3% (2 negative profit and 1 positive profit)
Student 456 - the winning rate is 100% (0 negative profit and 2 positive profit)
So, the final answer, average winning rate among all the students is:
(50% + 33.3% + 100%)/3 = 61.1%
61.1% is the final output that I want, then I will put this value into a Donut chart. I'm relatively new to DAX, any help or advise will be greatly appreciated!
Please paste text rather than images when providing sample data.
You shouldn't really add averages together like that but if that is definitely what you want, use Measure 2.
If you want a more traditional average to be calculated, use Measure 1.
Measure 1 =
VAR total = CALCULATE( COUNTROWS('Table'), ALLEXCEPT('Table','Table'[Student]))
VAR pos = CALCULATE(COUNT('Table'[Profit]), ALLEXCEPT('Table','Table'[Student]),'Table'[Profit] > 0)
RETURN pos/total
Measure 2 =
VAR students = CALCULATE(DISTINCTCOUNT('Table'[Student]), ALLEXCEPT('Table','Table'[Student]))
RETURN SUMX(VALUES('Table'[Student]), [Measure 1]/students)
I've started to manage PowerBi from a couple of weeks so i'm a little bit confused about some things.
My problem is that i need a Matrix in my dashboard with percent values but i want the total in number value because the total of a percent of row shows me always 100% and i dont know about the number i'm working
This is my Matrix with percentage values
This is how i want the total of row returns me but with the columns values ins percentage
I've tried to make a measure counting the values
COUNT(OPSRespuestas[answer])
After that turn off the total of rows and add this measure to the values in my matrix but this is what i get
This is my table after trying add a measure with the total
It returns me the total for each of the columns and not the total of all my rows.
These are the tables i'm working with
This my top header values
This is my left header values
The answer column is what i need to count
This is my relationship between this 3 tables although i have many more intermediate table aside from this 3 as you're going to see in the next picture:
My relationship tables
So finally what i need is that this matrix shows me the total of answer in percentage for each of departments and group of questions and then show me total by department but with number value
The problem you are experiencing has to do with context. Each row is seen as it own total population hence the 100% total. Each column in this row is evaluated against the total of that row to provide a percentage value.
In addition to adding a custom measure to replace the total, you could also consider computing a percentage against the grand total of all dimensions. This means that each cell gets evaluated against the the total of all rows and columns. In this ways the cell value would change compared to your first table but the row total does not evaluate to 100% anymore.
SUM ( [Value] ) / CALCULATE ( SUM ( [Value] ) ; ALL ( 'Your Table' ) )
I'm having issues creating a measure which calculates the total average.
I have a total teams column (team a, team b, team c) and a goals scored column ( 1, 3, 2)...
I created a measure which computes the total goals scored (by date) of the selected team (selected via a filter), and I need to compare that against the total average goals scored (by date).
Measure for total goals
= CALCULATE([TotalGoalScored],ALLSELECTED(Teams[Teams]))
and the subsequent
AverageGoals Scored = AVERAGEX('Teams',[TotalGoalScored])
However, when I drag both of these values to a viz, and select a "team" both values are the same, (i.e. it is computing the average goals scored for only the selected team which = total goals scored). When I select "All" teams, the average is being computed correctly. What alternate formula can I use to computer average?
So the problem is in the "AverageGoals Scored" measure, which shouldn't be affected by team filter?
If so, how about like this:
AverageGoals Scored = CALCULACE(AVERAGEX('Teams',[TotalGoalScored]), ALL(Teams[Teams]))
I have a quiz app where students can take tests. There is ranking based on every test. It's implemented with simple lists (Every new score is inserted into the list and then sorted (index+1 is the rank)).
But I want to add another abstraction. ie. Suppose 1000 students took the test and my ranking was 890. But those 1000 students should automatically be divided into 10 groups ie. group 1 of ranking 1 to 99, group2 of ranking 100 to 199 and so on. So if my overall ranking is 890. I should be subscribed to group 9 with 90th rank in that group.
How should this be implemented?
Just save the ranking score for every student. Calculate their group when you displaying them.
I have a household data set which includes expenditures for various foods. I categorized them into main food groups and price is obtained by dividing the expenditure value by quantity. For some households price comes as zero since their consumption with respect to the corresponding food group is zero. In such cases, I want to get the price as the average price of the corresponding city, district & province, which that non-consumed household is selected.
How could I do it using STATA?
The mean of the positive values is
egen mean_price = mean(price / (price > 0)), by(province district city)
and you can replace zeros in a clone by
gen price2 = cond(price > 0, price, mean_price)
The division trick can be explained like this. If price > 0 is true, then that expression evaluates to 1; and if false to 0. Dividing by 1 clearly leaves values unchanged. Dividing by 0 creates missings, which egen's mean() function will ignore, which is precisely what is wanted.
There is more discussion of related technique in the article referred to in http://www.stata-journal.com/article.html?article=dm0055
P.S. Stata is the correct spelling. It is an invented word, and was never an acronym.
P.S. You have yet to acknowledge an answer at How to get the difference of two variables, when there are missing values?
LATER:
In this case another way is
egen total = total(price), by(province district city)
egen number = total(price > 0), by(province district city)
gen price2 = cond(price > 0, price, total/number)
as zero prices make no difference to the total. Use doubles throughout.