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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
adoster
Resolver I
Resolver I

Replace Values from one table to another

Hi!

Created a simple version of what I am trying to do.

I have 2 tables. Relationship on column ID.

Want to replace "Code" values in main SQL_TableA with values from imported Excel_TableB when the Code value in Table A = "Error"

 

SQL_Table A:

IDCode
1Error
2Error
3Error
4Error
5Error
6X
7Y
8Z

 

 

Excel_TableB:

IDCode
1A
2B
3C
4D
5E

 

Desired Result:

SQL_TableA

IDCode
1A
2B
3C
4D
5E
6X
7Y
8Z

 

 

I tried the following in Power Query

= Table.ReplaceValue(
#"Changed Type",
#"SQL_TableA"[Code],
#"Excel_TableB"[Code],
Replacer.ReplaceText,{"Error"}
)

 

Result = Expression.Error: A cyclic reference was encoutnered during evaluation

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @adoster ,

 

In Power Query:

let
    Source = Table.NestedJoin(#"SQL_Table A", {"ID"}, Excel_TableB, {"ID"}, "Excel_TableB", JoinKind.FullOuter),
    #"Expanded Excel_TableB" = Table.ExpandTableColumn(Source, "Excel_TableB", {"ID", "Code"}, {"Excel_TableB.ID", "Excel_TableB.Code"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Excel_TableB", "Custom", each if [Code] = "Error" then [Excel_TableB.Code] else [Code]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Code", "Excel_TableB.ID", "Excel_TableB.Code"})
in
    #"Removed Columns"

Use DAX:

Column =
IF (
    'SQL_Table A'[Code] = "Error",
    LOOKUPVALUE ( Excel_TableB[Code], Excel_TableB[ID], 'SQL_Table A'[ID] ),
    'SQL_Table A'[Code]
)

 

Best Regards,

Jay 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @adoster ,

 

In Power Query:

let
    Source = Table.NestedJoin(#"SQL_Table A", {"ID"}, Excel_TableB, {"ID"}, "Excel_TableB", JoinKind.FullOuter),
    #"Expanded Excel_TableB" = Table.ExpandTableColumn(Source, "Excel_TableB", {"ID", "Code"}, {"Excel_TableB.ID", "Excel_TableB.Code"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Excel_TableB", "Custom", each if [Code] = "Error" then [Excel_TableB.Code] else [Code]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Code", "Excel_TableB.ID", "Excel_TableB.Code"})
in
    #"Removed Columns"

Use DAX:

Column =
IF (
    'SQL_Table A'[Code] = "Error",
    LOOKUPVALUE ( Excel_TableB[Code], Excel_TableB[ID], 'SQL_Table A'[ID] ),
    'SQL_Table A'[Code]
)

 

Best Regards,

Jay 

mh2587
Super User
Super User

Append both the tables with coulmn ID


✔ Answered? Mark as solution

Muhammad Hasnain | Super User • Fabric • Power BI • Data Engineering

Let's connect on LinkedIn

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.