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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

HELP - Return a value closest to the initial values and displaying an adjacent column.

Hello,

 

I'm struggling to solve this problem.

 

Below I have two tables and I'm trying to create a column in PBI where it returns the "Grade" base on how close "Base Salary" is to the "Median." The "Median" can be above or below "Base" as long as it the smallest distance (hopefully this makes sense).

 

galaxyseaotter_0-1706734886938.png

 

Any advice/pointers would be greatly appreciated!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

“Grade”

vnuocmsft_0-1706756056148.png

 

"Salary"

vnuocmsft_1-1706756083174.png

 

You will need to calculate the absolute difference between the 'Base Salary' from one table and 'Median' from the other table. Add a calculated column in the table with the 'Base Salary' to find the absolute difference for each row.

 

Absolute Difference = 
MINX(
    ADDCOLUMNS(
        'Grade', 
        "Difference", ABS('Grade'[Median] - 'Salary'[Base Salary])
    ), 
    [Difference]
)

 

vnuocmsft_2-1706756313566.png

 

Create a calculated column that determines the grade associated with the smallest absolute difference in each base salary.

 

Closest Grade = 
CALCULATE(
    FIRSTNONBLANK('Grade'[Grade], 1),
    FILTER(
        'Grade',
        ABS('Grade'[Median] - 'Salary'[Base Salary]) = [Absolute Difference]
    )
)

 

vnuocmsft_4-1706756563935.png

 

Here is the result

vnuocmsft_5-1706756595616.png

 

Regards,

Nono Chen

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

 

 

 

 

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.  Sow the expected result.  Also, do you want a calculated column or a measure?


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

Hi @Anonymous 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

“Grade”

vnuocmsft_0-1706756056148.png

 

"Salary"

vnuocmsft_1-1706756083174.png

 

You will need to calculate the absolute difference between the 'Base Salary' from one table and 'Median' from the other table. Add a calculated column in the table with the 'Base Salary' to find the absolute difference for each row.

 

Absolute Difference = 
MINX(
    ADDCOLUMNS(
        'Grade', 
        "Difference", ABS('Grade'[Median] - 'Salary'[Base Salary])
    ), 
    [Difference]
)

 

vnuocmsft_2-1706756313566.png

 

Create a calculated column that determines the grade associated with the smallest absolute difference in each base salary.

 

Closest Grade = 
CALCULATE(
    FIRSTNONBLANK('Grade'[Grade], 1),
    FILTER(
        'Grade',
        ABS('Grade'[Median] - 'Salary'[Base Salary]) = [Absolute Difference]
    )
)

 

vnuocmsft_4-1706756563935.png

 

Here is the result

vnuocmsft_5-1706756595616.png

 

Regards,

Nono Chen

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

 

 

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors