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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
nok
Advocate II
Advocate II

Find the nearest and highest value by ID

I have two tables that follow this structure:
Order

IDQty
1111000
2224500

 

Scale

ID      ScaleQty       
1111000
1112000
1115000
11110000
2223500
2226000
2229000

 

I'd like to create a new column in the Order table that, for each ID, checks the quantity ordered (in the Order[Qty] column) and finds the nearest and highest quantity in the Scale[ScaleQty] column. It can't be the largest Qty of them all (for example ID 111, it can't be 10000); so for ID 111 it needs to be the nearest and highest quantity to 1000, which in this case would be 2000.
The final result of this new column would be something like this:

IDQtyNewColumn
11110002000
22245006000


How can I do this?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calcualated column formula in the Orders table will work

=CALCULATE(MIN(Scale[ScaleQty]),FILTER(Scale,Scale[ID]=EARLIER('Order'[ID])&&[ScaleQty]>EARLIER('Order'[Qty])))

Hope this helps.

Ashish_Mathur_0-1752285053141.png

 


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

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This calcualated column formula in the Orders table will work

=CALCULATE(MIN(Scale[ScaleQty]),FILTER(Scale,Scale[ID]=EARLIER('Order'[ID])&&[ScaleQty]>EARLIER('Order'[Qty])))

Hope this helps.

Ashish_Mathur_0-1752285053141.png

 


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

pls try 


Screenshot_5.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.