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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Jestii
Regular Visitor

Matching two tables with criterias then return matching rows in Power Query without merge function

Hi, I have this problem 

Have several tables that I need to try to combine in one.
Main table = OLRR

Second table = OLMPDirekta

 

OLRR and OLMPDirekta I want to create a custom column called OLNyResultat in OLRR and the code should be something like this "if CostType = Absorption (DL) then match Date and CostCenter columns between OLRR and OLMPDirekta and return column DiffNyOLMPDirekta from OLMPDirekta"

the code I have so far with help from GTP is this 


"if [CostType] = "Absorption (DL)" then
let
matchingRows = Table.SelectRows(OLMPDirekta, each [Date] = [Date] and [CostCenter] = [CostCenter]),
result = if Table.RowCount(matchingRows) > 0 then matchingRows{0}[DiffNyOLMPDirekta] else null
in
result
else null"

But the problem here is that it's not returning the right answer except on the first match. 

 

Table OLMPDirekta

Jestii_1-1705936509079.png


Result in OLRR from the code above 

Jestii_2-1705936649870.png


It gives me result from 202301 which was 2 to all other months 202302, 202303 etc but these should be 1

Any ideas on how to make this work? 



2 REPLIES 2
slorin
Super User
Super User

Hi,

try

 

(x) => if [CostType] = "Absorption (DL)" then
let
matchingRows = Table.SelectRows(OLMPDirekta, each x[Date] = [Date] and x[CostCenter] = [CostCenter]),
result = if Table.RowCount(matchingRows) > 0 then matchingRows{0}[DiffNyOLMPDirekta] else null
in
result
else null

 

or

(x) => if [CostType] = "Absorption (DL)" then
List.First(
Table.SelectRows(OLMPDirekta, each x[Date] = [Date] and x[CostCenter] = [CostCenter])[DiffNyOLMPDirekta],

null)
else null

Stéphane

Hi, 

 

When I try both of the codes I get a function result. 
When I click on it I get this popup 

Jestii_0-1705946709393.png

I click Ok without typing in anything and the result is this

Jestii_1-1705946756135.png

 




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors