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
TStanifiorth
Advocate I
Advocate I

Merge in PowerQuery using filters and nearest values.

Hello I have an issue, which to abstract looks a bit like this:

 

Table 1: Inventory

 

IDItemValue

1

TV£30
2TV£40
3TV£90
4Radio£5
5Radio£10

 

Table2: InsuranceProduct

 

NameProdTypeMaxValue
TVOneTV£50
TVTwoTV£100
RadioOneRadio£8
RadioTwoRadio£16

 

I want to merge these two queries so I can add a column to the Inventory table with the relevant insurance product name, i.e.:

 

IDItemValueInsurance.Name

1

TV£30TVOne
2TV£40TVOne
3TV£90TVTwo
4Radio£5RadioOne
5Radio£10RadioTwo

 

I.e. in other words I want to look up a value in one table ([InsuranceProduct]"Name"), by matching on the value of one column ([Inventory]"Item" and [InsuranceProduct]"ProdType"), and finding the smallest value in [insuranceProduct]"MaxValue" that is greater than [Inventory]"Value"

 

I hope that makes sense!

3 REPLIES 3
wdx223_Daniel
Super User
Super User

=let a=Table.Group(InsuranceProduct,"ProdType",{"n",each Table.Sort(_,"MaxValue")}) in Table.AddColumn(Inventory,"InsuranceName",each let b=a{[ProdType=[Item]]}?[n]? in if b=null then null else Table.Skip(b,(x)=>x[MaxValue]<[Value]){0}?[Name]?)

This seems to throw a cyclic reference error?

wdx223_Daniel_0-1686182880384.png

it works well on my PC

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Kudoed Authors