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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare 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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Users online (1,752)