cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pye
Helper I
Helper I

Replace value from another table exclude null

Hi there!

 

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

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

pye_1-1685601015663.png

 

 

with the code below, I manage to replace the red wrong value in Table 1 with Table 2:

Table.FromRecords(Table.TransformRows(#"Table1",each _&(Table2{[year=[year],id=[id]]}? ??[])))

 

However, is it possible if can only replace those not null (exclude the grey cells in Table 2)? In table 1, row 3, energyusage.value of 600 is correct, so it is null in table 2 (grey cell), no need to replace null to table 1. How do with only replace the value in Table 2 to Table 1 if it contains a value, not replace if Table 2 is empty?

 

Thank you

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1685602349133.png

 

= Table.FromRecords(Table.TransformRows(Table1,each let a=Table2{[Year=[Year],ID=[ID]]}? in if a is null then _ else Record.TransformFields(_,Table.ToList(Table.SelectRows(Record.ToTable(a),each [Value]<>null and [Value]<>""),each {_{0},(x)=>_{1}}),1)))

View solution in original post

2 REPLIES 2
pye
Helper I
Helper I

works well which null is not replacing the value! thank you!

wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1685602349133.png

 

= Table.FromRecords(Table.TransformRows(Table1,each let a=Table2{[Year=[Year],ID=[ID]]}? in if a is null then _ else Record.TransformFields(_,Table.ToList(Table.SelectRows(Record.ToTable(a),each [Value]<>null and [Value]<>""),each {_{0},(x)=>_{1}}),1)))

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors