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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PQ
Regular Visitor

Vlookup - in one table based on 3 columns

On my monthly update with thousands of lines from the raw data list I need to replace in Power Query [External Tx ID] "rexxxxxx" (based on "refund" in [Tx Type] column) with "pixxxxxx" (based on original "purchase" in [Tx Type] column), which match as value "Uxxxx" (in [ID] column.

As a result, I need to Add Column with "pixxxxx" value on both lines, means of "purchase" and "refund" line, to be able to further work with it. Please could you help?
Please see more on the snapshot please to better understand my notes above.

 

PQ_0-1703449748171.png

 

 

5 REPLIES 5
Anonymous
Not applicable

Hi @PQ ,

Sorry I can't check out exactly what the problem is, can you see if there are any error tips you can provide me with?
Or you can remove the Table.AddColumn at the beginning of the previous code, i.e., the M code becomes like this and try to see if it still reports errors:

= if [Tx Type] = "purchase" then [External Tx ID]
else if [Tx Type] = "refund" then 
let 
currentID = [ID],
relatedPurchase = 
Table.SelectRows(Source, each ([ID] = currentID and [Tx Type] = "purchase"))
in 
if Table.IsEmpty(relatedPurchase) then null else relatedPurchase{0}[External Tx ID]
else null

vjunyantmsft_0-1704097437741.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PQ
Regular Visitor

PQ_4-1703519359564.png

 

 

PQ
Regular Visitor

PQ_0-1703519039716.pngPQ_1-1703519105098.pngPQ_2-1703519135555.png

 

PQ
Regular Visitor

Hi, thank you for the quick reply. Very much appreciated.

I might do something wrong because I see on your tab it should work, but not for me for some reason, showing error - snapshot below.

Anonymous
Not applicable

Hi @PQ ,

You can try this M code:

= Table.AddColumn(Source, "Custom External ID", each 
if [Tx Type] = "purchase" then [External Tx ID]
else if [Tx Type] = "refund" then 
let 
currentID = [ID],
relatedPurchase = 
Table.SelectRows(Source, each ([ID] = currentID and [Tx Type] = "purchase"))
in 
if Table.IsEmpty(relatedPurchase) then null else relatedPurchase{0}[External Tx ID]
else null)

The results are as follows:

vjunyantmsft_0-1703487076528.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.