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
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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors