Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ThomasKieny
New Member

Calculation of difference between salary and average salary for a given position

Hi everyone, 

I'm new to Power BI and DAX and would need a little help on a calculation that looks pretty basic... 
I have a table that looks like this: 

ThomasKieny_0-1704034093091.png

 

I want to create a column, in which I'll have the difference between the employee's salary and the average salary for this position (column [Position]). Then I could rapidly see if this employee has a salary below or above the average for this job. 

Thank you for your help !

2 ACCEPTED SOLUTIONS
Dangar332
Super User
Super User

Hi, @ThomasKieny 

for difference bw salary and average
try below column formula

for difference = 
var a = AVERAGEX(FILTER('Table (3)','Table (3)'[position]=EARLIER('Table (3)'[position])),'Table (3)'[salary])
var b = ABS('Table (3)'[salary] - a)
return
b

 

for above and below

above and below = 
var a = AVERAGEX(FILTER('Table (3)','Table (3)'[position]=EARLIER('Table (3)'[position])),'Table (3)'[salary])
RETURN
IF('Table (3)'[salary]<a,"below","above")

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Try these calculated column formulas

Average salary of position = calculate(average(Data[Salary]),filter(data,data[position]=earlier(data[position])))

Status = if(data[Salary]>data[Average salary of position],"Above",if(data[Salary]<data[Average salary of position],"Below","Same"))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Try these calculated column formulas

Average salary of position = calculate(average(Data[Salary]),filter(data,data[position]=earlier(data[position])))

Status = if(data[Salary]>data[Average salary of position],"Above",if(data[Salary]<data[Average salary of position],"Below","Same"))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Dangar332
Super User
Super User

Hi, @ThomasKieny 

for difference bw salary and average
try below column formula

for difference = 
var a = AVERAGEX(FILTER('Table (3)','Table (3)'[position]=EARLIER('Table (3)'[position])),'Table (3)'[salary])
var b = ABS('Table (3)'[salary] - a)
return
b

 

for above and below

above and below = 
var a = AVERAGEX(FILTER('Table (3)','Table (3)'[position]=EARLIER('Table (3)'[position])),'Table (3)'[salary])
RETURN
IF('Table (3)'[salary]<a,"below","above")
rubinboer
Resolver II
Resolver II

hi @ThomasKieny   

 

if you want to add a column you can do this:

Compare to Avg = IF( YourTable[Salary] > AVERAGE(YourTable[Salary]), "Above", "Below")
The above will not yield the result, i missed the part of salary avg per job. the below will work:
Compare to Avg =
VAR AvgPerPosition =
    AVERAGEX(  
        FILTER(
        //here the table called "Salaries whic is your table" is filtered to add only rows with teh same position
            Salaries, [Position] = EARLIER([Position])
        ),
        [Salary]
    )

RETURN
SWITCH(
    TRUE(), Salaries[Salary] = AvgPerPosition, "The Same",
    Salaries[Salary] > AvgPerPosition, "Above",
    Salaries[Salary] < AvgPerPosition,"Below"
)

Result:
rubinboer_1-1704100245326.png

 

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.