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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Vlookup numbers in a range (power Query)

I am trying to lookup a value from my main table into a scale that is in a second table.

 

Main table

RouteRegionMilesDesired return
A120 
B225 

 

Scale table

RegionMin MilesMax MilesWeight
10210.15
121500.3
20210.2

 

I need a method to lookup the value of miles from the main table into the scale table. This will be done according to the region. The formula that I need will essentially say ... y value of miles is in region x, and miles y is between these to values, so the return will be equal to the corresponding weight. Does anyone know how to perform a formula like this in Power Query?

 

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

1.You can merge the two tables first, and then add a custom column to calculate the expected return value.

3.png

 

2.Expand the fields you want.

4.png

5.png

 

3.Add a custom column to find the region within miles. Then filter the custom column.

7.png8.png9.png

 

4.The result is as follows.

11.png

 

Best Regards,

Stephen Tao

 

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
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

1.You can merge the two tables first, and then add a custom column to calculate the expected return value.

3.png

 

2.Expand the fields you want.

4.png

5.png

 

3.Add a custom column to find the region within miles. Then filter the custom column.

7.png8.png9.png

 

4.The result is as follows.

11.png

 

Best Regards,

Stephen Tao

 

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

mahoneypat
Employee
Employee

This could be done in the query editor, but it is more suited to DAX, either as a measure or a calculated column.  You should do a measure as a first choice and only do columns when needed.  However, the measure will depend on the columns used in your visuals, so here is an example of a DAX column expression you can use on your Main table.

 

Weight =
VAR ThisRegion = Main[Region]
VAR ThisMiles = Main[Miles]
VAR Result =
    CALCULATE (
        MIN ( Scale[Weight] ),
        Scale[Region] = ThisRegion,
        Scale[MinMiles] <= ThisMiles,
        Scale[MaxMiles] >= ThisMiles
    )
RETURN
    Result

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors