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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Simon_1981
Frequent Visitor

Return a value after checking two values within the right ranges

Hi, 

I am trying to figure out how to get the right value (i.e. Color) from a weight / volume table in a products table with power query M. The returned value (color) needs to meet both criteria, the right value from a weight range and the right value from a volume range.

 

Table: Numbers

2024-09-07_00h03_34.png

 

Table: Products

2024-09-07_00h03_46.png

 

I already experimented the following code:

 

Table.SelectRows(Numbers,(x)=> x[Weight from]<=[Weight] and x[Weight to] >=[Weight])[Color]


I did not find a way to combine this with the second check for the right volume.

 

This is my goal:

2024-09-07_00h06_33.png

 

Can any of you experts help me out on that? 

Thank you very much in advance. 

 

Many regards,

Simon

 

NB: I am sorry for posting with photos instead of tables with data. I tried to post with copy and pasted tables first but my posts got rejected twice.

1 ACCEPTED SOLUTION
Claude_Xu
Frequent Visitor

Hi Simon,

 

Your direction is right, and overall you can implement that by

1. add a column holding the corresponding Numbers records

2. expand that newly added column which holds records and pick the Color column

 

let
Numbers = Excel.CurrentWorkbook(){[Name="Numbers"]}[Content],
Product = Excel.CurrentWorkbook(){[Name="Product"]}[Content],
#"Add ColorTable Col" = Table.AddColumn(Product, "ColorTable",
(ProdRow as record) =>
Table.SelectRows(
Numbers,
each [Weight from] <= ProdRow[Weight] and ProdRow[Weight] <= [Weight to]
and [Volume from] <= ProdRow[Volume] and ProdRow[Volume] <= [Volume to]
)
),
#"Expand Col" = Table.ExpandTableColumn(#"Add ColorTable Col", "ColorTable", {"Color"})
in
#"Expand Col"

 

Claude_Xu_0-1725676270926.png

 

View solution in original post

4 REPLIES 4
Simon_1981
Frequent Visitor

Good morning Claude_Xu,

 

you made it look so easy. Thank you so much for your help and for your solution -that's awesome!

 

Many regards,

 

Simon

lbendlin
Super User
Super User

What if the weight is 5.5?  what if the volume is 0.1355 ?

Good morning Ibendlin,

 

I assume then the weight or the volume has to be rounded up to the next corresponding color.

Those numbers I used in the example are not made up by me but are actual numbers of shockwatch labels.

 

Many regards,

 

Simon

Claude_Xu
Frequent Visitor

Hi Simon,

 

Your direction is right, and overall you can implement that by

1. add a column holding the corresponding Numbers records

2. expand that newly added column which holds records and pick the Color column

 

let
Numbers = Excel.CurrentWorkbook(){[Name="Numbers"]}[Content],
Product = Excel.CurrentWorkbook(){[Name="Product"]}[Content],
#"Add ColorTable Col" = Table.AddColumn(Product, "ColorTable",
(ProdRow as record) =>
Table.SelectRows(
Numbers,
each [Weight from] <= ProdRow[Weight] and ProdRow[Weight] <= [Weight to]
and [Volume from] <= ProdRow[Volume] and ProdRow[Volume] <= [Volume to]
)
),
#"Expand Col" = Table.ExpandTableColumn(#"Add ColorTable Col", "ColorTable", {"Color"})
in
#"Expand Col"

 

Claude_Xu_0-1725676270926.png

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors