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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
pye
Helper I
Helper I

Replace value from another table if the columns appear

Hi there!

 

I have 1st table here with some incorrect data and would like to replace it based on the 2nd table.

The value in red font is wrong, the correct data is in 2nd table.

pye_0-1677223011194.png

 

I would like to change the waterusage.value for ID 21345 at year 2021 to 50, instead of 12000 in table 1. Similar to waterusage.value of ID 9281 at year 2021, change to 300 instead of 40000. 

pye_1-1677223066375.png

 

I tried to use table.replacevalue(#"Added Custom", each [waterusage.value], each if Table2{[waterusage.value] = value then Table2[waterusage.value], Replacer.ReplaceText,{"waterusage.value"})

 

But I notice it is not feasible because there might be addtional columns in table 2, such as if we found more incorrect data in table 1, we will need to add new column in table 2 like energyusage.value, wastedisposal.value. Is there any way if we not hard code the column name and the code will directly take table 2 value if it found the column there?

 

Thank you

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

suppose the bound value of year and  ID in table 2 is unique, you can try this code.

NewStep in Table1=Table.FromRecords(Table.TransformRows(Table1,each _&(Table2{[Year=[Year],ID=[ID]]}? ??[])))

View solution in original post

2 REPLIES 2
pye
Helper I
Helper I

yes, they are unique. and the code works well! thank you!

wdx223_Daniel
Super User
Super User

suppose the bound value of year and  ID in table 2 is unique, you can try this code.

NewStep in Table1=Table.FromRecords(Table.TransformRows(Table1,each _&(Table2{[Year=[Year],ID=[ID]]}? ??[])))

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.