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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
KasperJ90
Helper III
Helper III

Power Query code for lookup value in a range in another table and return text from that table

Hi all,

 

I have a tabel with a range of "Minute Type". I want to add the "Minute Type" to each line in tabel Prod Line based on the No_ as a calculated column:

Tabel Range

KasperJ90_0-1664221839113.png

 

 

Tabel Prod Line

KasperJ90_1-1664221839111.png

 

So as an example I would like to add Minute Type "Cutting Minutes" to the first row with No_ 0900 and "Lamination Minuts" to the second row.

 

How can I do this in Power Query (not DAX)?

 

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

Hi @KasperJ90 ,

According to your description, here's my solution.

1. Power Query.

Add a custom column in Prod Line table.

Table.SelectRows(Range,(x)=> x[Operation From]<=[No_] and x[Operation To] >=[No_])[Minute Type]

Then expand the column, get the correct result.

vkalyjmsft_1-1664435629596.png

2. DAX

Create a calculated column in Prod Line table.

Column =
MAXX (
    FILTER (
        'Range',
        'Range'[Operation From] <= EARLIER ( 'Prod Line'[No_] )
            && 'Range'[Operation To] >= EARLIER ( 'Prod Line'[No_] )
    ),
    'Range'[Minute Type]
)

Get the correct result.

vkalyjmsft_0-1664434803742.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

3 REPLIES 3
v-yanjiang-msft
Community Support
Community Support

Hi @KasperJ90 ,

According to your description, here's my solution.

1. Power Query.

Add a custom column in Prod Line table.

Table.SelectRows(Range,(x)=> x[Operation From]<=[No_] and x[Operation To] >=[No_])[Minute Type]

Then expand the column, get the correct result.

vkalyjmsft_1-1664435629596.png

2. DAX

Create a calculated column in Prod Line table.

Column =
MAXX (
    FILTER (
        'Range',
        'Range'[Operation From] <= EARLIER ( 'Prod Line'[No_] )
            && 'Range'[Operation To] >= EARLIER ( 'Prod Line'[No_] )
    ),
    'Range'[Minute Type]
)

Get the correct result.

vkalyjmsft_0-1664434803742.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

tackytechtom
Super User
Super User

Hi @KasperJ90 ,

 

How about this:

tomfox_0-1664223414814.png

 

 

The idea is to first unfold the rows in the Range table and afterwards joining it in onto the ProdLine table.

 

1. Create a new Custom Column in Range with the following code:

tomfox_1-1664223565209.png

{ Number.From ( [Operation From] ) ..Number.From ( [Operation To] ) }

 

2. Unfold the list:

tomfox_2-1664223595416.png

 

This unfolding technique is pretty useful. Here a blog post about this:

https://www.tackytech.blog/how-to-swiftly-take-over-power-query/#unfold-expand-create-rows-between-t...

 

 

 

3. Merge the query into the ProdLine:

tomfox_3-1664223681418.pngtomfox_4-1664223706894.png

 

4. Expand the column Minute Range from the new Range Column:

tomfox_5-1664223756682.png

 

Let me know if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi @tackytechtom 
Thank you for this detailed answer. It works yes - but I would rather include it as "lookup" function instead of merge queries. Can you help me make custom column in prod line with a function that looks in "range" table? 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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