ID 18 - counts the number of employees whose job description is 'Manager'

Max: 45
Try code in DAX.do

Syntax

CALCULATE COUNT COUNTROWS ROW SUM SUMMARIZE SUMMARIZECOLUMNS

Related

19 - Calculate the average salary of managers 42 - Crossjoin to Count Products by Color and Category 44 - Calculate Total Sales by Product Brand Over the Last 6 Months 20 - Calculate the sum of salaries for analysts

SQL

SELECT COUNT(*) AS Count_of_manager 
FROM employee 
WHERE job_desc = 'Manager';

DAX

EVALUATE
SUMMARIZECOLUMNS (
    "Count_of_manager", 
    CALCULATE (
        COUNTROWS ( employee ),
        employee[job_desc] = "Manager"
    )
)

Pandas

import pandas as pd

# Sample DataFrame
data = {
    'employee_id': [1, 2, 3, 4, 5],
    'job_desc': ['Manager', 'Clerk', 'Manager', 'Analyst', 'Manager']
}

df = pd.DataFrame(data)

# Count the number of managers
count_of_manager = df[df['job_desc'] == 'Manager'].shape[0]

# Result in list of lists
result = [['Count_of_manager', count_of_manager]]
print(result)

Output

Count_of_manager 3

Explanation

CALCULATE(COUNTROWS(employee), employee[job_desc] = "Manager"): This calculates the number of rows in the employee table where the job_desc column is equal to 'Manager'. SUMMARIZECOLUMNS: Creates a table with a single column named Count_of_manager that contains the count of managers.

Leave a Comment