Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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?

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous ,

     

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

     

    2.Expand the fields you want.

     

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

     

    4.The result is as follows.

     

    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.

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft 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

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

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

     

    2.Expand the fields you want.

     

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

     

    4.The result is as follows.

     

    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.