ID 22 - Calculate the maximum salary

Max: 45
Try code in DAX.do

Syntax

CALCULATE MAX SUM SUMMARIZE SUMMARIZECOLUMNS

Related

44 - Calculate Total Sales by Product Brand Over the Last 6 Months

SQL

SELECT MAX(salary) AS Max_Salary 
FROM employee;

DAX

EVALUATE
SUMMARIZECOLUMNS (
    "Max_Salary", 
    CALCULATE (
        MAX(employee[salary])
    )
)

Pandas

import pandas as pd

# Sample DataFrame
data = {
    'employee_id': [1, 2, 3, 4, 5],
    'job_desc': ['Manager', 'Clerk', 'Manager', 'Analyst', 'Analyst'],
    'salary': [70000, 50000, 80000, 60000, 120000]
}

df = pd.DataFrame(data)

# Calculate the maximum salary
max_salary = df['salary'].max()

# Result in list of lists
result = [['Max_Salary', max_salary]]
print(result)

Output

Max_Salary 120000

Explanation

CALCULATE(MAX(employee[salary])): This calculates the maximum salary from the employee table. SUMMARIZECOLUMNS: Creates a table with a single column named Max_Salary that contains the maximum salary.

Leave a Comment