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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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