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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors