The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am trying to lookup a value from my main table into a scale that is in a second table.
Main table
Route | Region | Miles | Desired return |
A | 1 | 20 | |
B | 2 | 25 |
Scale table
Region | Min Miles | Max Miles | Weight |
1 | 0 | 21 | 0.15 |
1 | 21 | 50 | 0.3 |
2 | 0 | 21 | 0.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?
Solved! Go to Solution.
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.
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.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.