Forum Discussion

avou26's avatar
avou26
Frequent Visitor
3 years ago
Solved

Sum and Average Salary by Category

Hello! I am trying to create a visual that shows the average salary per each position type. My data set has each payment that was made over the year to each person. Is there a dax that will total the amount paid out and then average by position? 

 

  • Hi avou26 

    If i understand you correctly

    Sum of salary

    Salary_by_category = sumx(values('yourtable'[earnings job description]), Sum([amount])

    Average

    AVG_by_category = Averagex(values('yourtable'[earnings job description]), average([amount])

    if not 

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
    Please show the expected outcome based on the sample data you provided.

    https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi avou26 ,

    Please try below steps:

    1. below is my test table

    Table:

     

    2. create measure with below dax formula

    Sum Amount Per Job = SUM('Table'[Amount])
    Average Per Job =
    VAR cur_job =
        SELECTEDVALUE ( 'Table'[Earnings Job Description] )
    VAR tmp =
        FILTER ( ALL ( 'Table' ), [Earnings Job Description] = cur_job )
    VAR a =
        SUMX ( tmp, [Amount] )
    VAR b =
        COUNTROWS ( CALCULATETABLE ( VALUES ( 'Table'[Employee Number] ), tmp ) )
    RETURN
        DIVIDE ( a, b )
    

    3. add a Clustered column chart with field and measure

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Hi avou26 

    To achieve a goal I used 2 measures.

    for sum :

    Sum_Salary = sum('Table'[Amount])
    for average 
    Average+Per_employee = SUMX(values('Table'[Employee Number]),[Sum_Salary])/DISTINCTCOUNT('Table'[Employee Number])

    Link to the sample file 

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi avou26 ,

    Please try below steps:

    1. below is my test table

    Table:

     

    2. create measure with below dax formula

    Sum Amount Per Job = SUM('Table'[Amount])
    Average Per Job =
    VAR cur_job =
        SELECTEDVALUE ( 'Table'[Earnings Job Description] )
    VAR tmp =
        FILTER ( ALL ( 'Table' ), [Earnings Job Description] = cur_job )
    VAR a =
        SUMX ( tmp, [Amount] )
    VAR b =
        COUNTROWS ( CALCULATETABLE ( VALUES ( 'Table'[Employee Number] ), tmp ) )
    RETURN
        DIVIDE ( a, b )
    

    3. add a Clustered column chart with field and measure

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Hi avou26 

    If i understand you correctly

    Sum of salary

    Salary_by_category = sumx(values('yourtable'[earnings job description]), Sum([amount])

    Average

    AVG_by_category = Averagex(values('yourtable'[earnings job description]), average([amount])

    if not 

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
    Please show the expected outcome based on the sample data you provided.

    https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

    • avou26's avatar
      avou26
      Frequent Visitor

      Sorry about that! Thank you for your response Ritaf1983 . Here is some sample data- i realize with my initial question that i didn't include that the employees have unique ID numbers. I would like to sum the amount per each job description category, and average it using the amount of employees(hopefully with the id number) to see what the average pay per each category is.  At the end I hope to create a bar chart visual that shows the topN paying positions in the organization based on average pay. The issue i keep running into is it is only totalling all positions and averaging based on every line, not the unique employee number

       

      Employee NumberAmountEarnings Job Description
      111831,761.20ACCOUNT CLERK
      112181,761.20ACCOUNT CLERK
      112181,761.20ACCOUNT CLERK
      112181,761.20ACCOUNT CLERK
      111831,749.25ACCOUNT CLERK
      111831,736.43ACCOUNT CLERK
      115611,717.10ACCOUNT CLERK
      115611,717.10ACCOUNT CLERK
      107382,941.96AUDITOR
      107382,922.61AUDITOR
      383882,904.00AUDITOR
      383882,904.00AUDITOR
      383882,904.00AUDITOR
      48980214.90CASEWORKER
      48980214.90CASEWORKER
      47590214.90CASEWORKER
      47590214.90CASEWORKER
      47590214.90CASEWORKER
      47590214.90CASEWORKER
      39041214.88CASEWORKER
      46927214.38CASEWORKER
      47079214.38CASEWORKER
      46198213.22CASEWORKER
      46927213.22CASEWORKER
      389071,950.10FISCAL OFFICER
      498591,930.11FISCAL OFFICER
      498591,792.25FISCAL OFFICER
      102601,627.15FISCAL OFFICER
      102601,627.15FISCAL OFFICER
      498591,605.14FISCAL OFFICER
      102601,603.91FISCAL OFFICER
      • Ritaf1983's avatar
        Ritaf1983
        Icon for Super User rankSuper User

        Hi avou26 

        To achieve a goal I used 2 measures.

        for sum :

        Sum_Salary = sum('Table'[Amount])
        for average 
        Average+Per_employee = SUMX(values('Table'[Employee Number]),[Sum_Salary])/DISTINCTCOUNT('Table'[Employee Number])

        Link to the sample file 

        If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly