cancel
Showing results for 
Search instead for 
Did you mean: 
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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors