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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

Find next highest value

Hi there,

 

I'm having trouble to find the next highest value in a column. 
In one table i have the actual zone and number of kilo's in a row. I need a calculated column (or by measure) to calculate the rate for that specific row. The kilo's, zone and rate are in a separate table and that table looks like below. 

KGZoneRate
116.29
128.50
139.00
216.75
229.25
2310.00
318.50
3210.00
5311.00
719.50
8211.50
9313.00

 

Example: if KG = 2.5 & zone = 2 is should select the rate of 10.00. This means that it needs to look at the table and if the specific weight is not available it must look to the next highest value within that zone and select that rate. In this case it is rounding 2.5 to 3.

Example 2: if KG = 6 & zone = 3 is should select the rate of 13.00. 

I was able to make the calculated column myself but only when the weight was exactly matching the KG in the column. The issue i'm having is that i'm not able to write the code to look for the next highest value in the column based on another column. 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Table1:

vzhangti_0-1695954146858.png

Table2:

Column = 
Var _nexthighKG=CALCULATE(MIN(Table1[KG]),FILTER(Table1,[KG]>=EARLIER(Table2[KG])&&[Zone]=EARLIER(Table2[Zone])))
Return
CALCULATE(MAX(Table1[Rate]),FILTER(Table1,[KG]=_nexthighKG&&[Zone]=EARLIER(Table2[Zone])))

vzhangti_1-1695954186585.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
Anonymous
Not applicable

@v-zhangti is there also a way to do this with a measure ?

Anonymous
Not applicable

After the weekend, with a fresh mind, i tried it again and it seems i made a mistake the first time.
This is working.

 

Thank you @v-zhangti 

Anonymous
Not applicable

Hi @v-zhangti 
Thank you for your help.
I applied the provided code but i gives an error "EARLIER/EARLIEST refers to an earlier row context which doesn't exist"

v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Table1:

vzhangti_0-1695954146858.png

Table2:

Column = 
Var _nexthighKG=CALCULATE(MIN(Table1[KG]),FILTER(Table1,[KG]>=EARLIER(Table2[KG])&&[Zone]=EARLIER(Table2[Zone])))
Return
CALCULATE(MAX(Table1[Rate]),FILTER(Table1,[KG]=_nexthighKG&&[Zone]=EARLIER(Table2[Zone])))

vzhangti_1-1695954186585.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.