Power BI Practice: Creating a Median Salary Reference Line in Power BI Clustered Column Chart
Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).
Scenario:
You have a clustered column chart that contains a measure named Salary as the value and a field named Employee as the axis. Salary is present in the data as numerical amount representing US dollars. You need to create a reference line to show which employees are above the median salary.
Solution: You create a median line by using the Salary measure. Does this meet the goal?
Answer: Yes, creating a median line using the Salary measure will meet the goal of showing which employees are above the median salary. By adding this reference line to your clustered column chart, you can easily visualize and compare each employee's salary against the median salary. This will help you identify which employees are earning above the median salary.
Step-by-step Guide
To create a median line in Power BI:
[1] Import the Data: Load this table into Power BI.
[2] Create the Clustered Column Chart:
• Drag the "Employee Name" field to the Axis area.
• Drag the "Salary" field to the Values area.
[3] Add a Median Line:
• Go to the Analytics pane (the magnifying glass icon).
• Select "Median Line" and add it to your chart.
• Customize the line as needed (e.g., change the color, style, etc.).
[4] (Optional) Create a measure to calculate media for checking purpose.
• Go to the "Modeling" tab on the ribbon. Click on "New Measure".
• Enter the following DAX formula to create a measure for the median salary:
Median Salary = MEDIAN('employee'[Salary])
[5] Review and Save:
• Review the chart to ensure the reference line is correctly placed at the median salary.
• Save your Power BI report.
Sample Data
Here's a sample table you can use to practice calculating the median salary and adding it as a constant line in a clustered column chart:
| Employee ID | Employee Name | Salary (USD) |
| 1 | Alice | 70,000 |
| 2 | Bob | 55,000 |
| 3 | Charlie | 60,000 |
| 4 | David | 80,000 |
| 5 | Eve | 75,000 |
| 6 | Frank | 65,000 |
| 7 | Grace | 90,000 |
| 8 | Hannah | 50,000 |
| 9 | Ian | 85,000 |
| 10 | Jane | 95,000 |
You can create this table in Power BI and follow the steps to calculate the median salary and add it as a constant line in your clustered column chart

.