Forum Discussion

Heartlyforjesus's avatar
Heartlyforjesus
Regular Visitor
4 years ago

Power Bi Customised comparison bar chart

I have a list of students with their marks based on three subjects. Students are from various cities.

 

 
Student NameCity SubjectMarks
Student 1City 1Maths96
Student 1City 1Chemistry56
Student 1City 1Physics89
Student 2City 1Maths56
Student 2City 1Chemistry89
Student 2City 1Physics45
Student 3City 2Maths78
Student 3City 2Chemistry25
Student 3City 2Physics96
Student 4City 2Maths85
Student 4City 2Chemistry75
Student 4City 2Physics45
Student 5City 1Maths78
Student 5City 1Chemistry95
Student 5City 1Physics46
Student 6City 2Maths85
Student 6City 2Chemistry78
Student 6City 2Physics98

 

I wanted to show a comparison bar graph of a student with other students depending on the selected student city.

If I selected Student 1, then I should get all other students of Student 1' city(City 1) and compare their marks based on their marks like Student 1 mark vs the aggregate of other students' marks.

 


I am able to bring the chart like above comparing student with other students. Only the problem now it should be compared the student with other students where the city is only the selected student city.

If I choose Student 1, it should take only the students of the City 1 for the comparison. 

I transformed the table like below,

 

 
I created the Student + Others table 

 

 

 

 

Students + Others =
UNION(
VALUES(Sheet1[Student Name]),
ROW("Student Name", "Others")
)

 

Created another mesaures like the below,

 

 

 

 

Marks vs Others =
VAR CurrentStudent = MAX('Students + Others'[Student Name])
VAR SelectedStudents = ALLSELECTED(Sheet1[Student Name])
VAR PossibleStudents = ALL(Sheet1[Student Name])
RETURN
SWITCH(
TRUE(),
CurrentStudent IN SelectedStudents,
CALCULATE(
[Total Marks],
Sheet1[Student Name] = CurrentStudent
),
CurrentStudent = "Others",
CALCULATE(
[Total Marks],
FILTER(
ALL(Sheet1[Student Name]),
Sheet1[Student Name] IN PossibleStudents
&& NOT(Sheet1[Student Name] In SelectedStudents)
)
)

)

 
I made the chart now like the below fields 

 

 

Now my only problem is, If I select Student 1, it should take the students of the city what the city of Student 1.
In my case it should take only Student 2 and Student 5 for the comparison for Student 1.  

3 Replies