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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
TStanifiorth
Regular Visitor

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors