cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hazaaa
Regular Visitor

Replaces value in table if row is present in other table

Hi i have Table 1 and Table 2. I want to replace values in table 1 if that value is null and that row is also present in Table 2 but i do not know how to accomplish this in power query

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @hazaaa ,

You can try this query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWJVnICssAMZyDDDMxyAbLMwSxXIMtYKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Value", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Table 2", {"Name"}, "Table 2", JoinKind.LeftOuter),
    #"Expanded Table 2" = Table.ExpandTableColumn(#"Merged Queries", "Table 2", {"Value"}, {"Table 2.Value"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Table 2",null,each [Table 2.Value],Replacer.ReplaceValue,{"Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Table 2.Value"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Value", Int64.Type}})
in
    #"Changed Type1"

t1.pngnt1.png

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @hazaaa ,

You can try this query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWJVnICssAMZyDDDMxyAbLMwSxXIMtYKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Value", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Table 2", {"Name"}, "Table 2", JoinKind.LeftOuter),
    #"Expanded Table 2" = Table.ExpandTableColumn(#"Merged Queries", "Table 2", {"Value"}, {"Table 2.Value"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Table 2",null,each [Table 2.Value],Replacer.ReplaceValue,{"Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Table 2.Value"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Value", Int64.Type}})
in
    #"Changed Type1"

t1.pngnt1.png

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Vera_33
Solution Sage
Solution Sage

Hi @hazaaa 

 

Can you provide some sample data in a format which we can copy? And expected result as well.

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors