Forum Discussion

Student986394's avatar
Student986394
New Member
1 year ago
Solved

Formula for average pay by gender

I'm basically trying to put the average pay by gender and by age in the table but I can't find a formula that is working can someone help me   
  • Anonymous's avatar
    Anonymous
    1 year ago

    HI, Student986394 

    Based on your information, I create a saple table:

     

    Then create a column, try the following DAX expression:

    AgeGroup = SWITCH(
        TRUE(),
        'Table'[Age] >= 20 && 'Table'[Age] <= 30, "20-30",
        'Table'[Age] >= 31 && 'Table'[Age] <= 40, "31-40",
        'Table'[Age] >= 41 && 'Table'[Age] <= 50, "41-50",
        "Other"
    )

     

    Create a new measure, here is my dax:

    AveragePayByGenderAndAgeGroup = 
    CALCULATE(
        AVERAGE('Table'[Pay]),
        ALLEXCEPT('Table', 'Table'[Gender], 'Table'[AgeGroup])
    )

     

    Put measure and fields in table visual. Here is my preview:

     

    How to Get Your Question Answered Quickly

    Best Regards

    Yongkang Hua

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