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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ktbb5757
Regular Visitor

Replace values in up to 2 columns based on table values

Hi all - Relatively new user here. 

 

I have two columns in table "Main." One is "Issue Type" and the other is "Subcategory." The underly data is part of a investigation case management system where each case is assigned an issue type and then a subcategory. Some of these values have changed over the years and we want to update the older values with the new ones.

 

I have mapped all the old values to their new corresponding value in a separate table (Issue Map). My data might look something like this:

 

ktbb5757_0-1726167660180.png

 

Depending on each situation, I might need to change the issue type, the subcategory, both, or neither.

I've not been able to locate a solution online for this, but I'm guess that has more to do with me asking the wrong question. Any help would be greatly appreciated.

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ktbb5757 ,
You can try the follwing code

let
    MainTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYw7CsNADAWvsqj2KfIjIaRJysXFWmhBWJaCVi58e29M2nkzL2c4OU/kGwxwXb5iG1F6Ms5TwRnGIcPZtApjJKvpoUFOLbr84oYkUpRsbYf4IVyd4/d0K9K4MpZg02O8vzu+9MZ5Yf3zcQc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Prior Issue Type" = _t, #"Prior Subcategory" = _t]),
    IssueMapTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspMSi2qVNJRcs7PzU0tykxOzFGAisXqRCt5BAGlAlKLivPzgBJBqTmJJZn5ecUZmQXFCHm3xJzizDSgVpCcUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"New Issue Type" = _t, #"New Subcategory" = _t]),
    MainWithIndex = Table.AddIndexColumn(MainTable, "Index", 0, 1, Int64.Type),
    IssueMapWithIndex = Table.AddIndexColumn(IssueMapTable, "Index", 0, 1, Int64.Type),
    MergedTables = Table.NestedJoin(MainWithIndex, "Index", IssueMapWithIndex, "Index", "IssueMap", JoinKind.FullOuter),
    ExpandedTable = Table.ExpandTableColumn(MergedTables, "IssueMap", {"New Issue Type", "New Subcategory"}),
    ReplacedTable = Table.AddColumn(ExpandedTable, "Current Issue Type", each if [New Issue Type] = null then [Prior Issue Type] else [New Issue Type]),
    ReplacedTable2 = Table.AddColumn(ReplacedTable, "Current Subcategory", each if [New Subcategory] = null then [Prior Subcategory] else [New Subcategory]),
    FinalTable = Table.SelectColumns(ReplacedTable2, {"Current Issue Type", "Current Subcategory"})
in
    FinalTable

Final output

vheqmsft_0-1726209195896.png

 

Best regards,
Albert He


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

4 REPLIES 4
dufoq3
Super User
Super User

Hi @ktbb5757, different approach:

 

Output

dufoq3_0-1726915082021.png

let
    MainTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYw7CsNADAWvsqj2KfIjIaRJysXFWmhBWJaCVi58e29M2nkzL2c4OU/kGwxwXb5iG1F6Ms5TwRnGIcPZtApjJKvpoUFOLbr84oYkUpRsbYf4IVyd4/d0K9K4MpZg02O8vzu+9MZ5Yf3zcQc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Prior Issue Type" = _t, #"Prior Subcategory" = _t]),
    IssueMapTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcirKTEotqlTSUXLOz81NLcpMTsxRcIKIxepEK3kEAaUCUouK8/OAEkGpOYklmfl5xRmZBcUIebfEnOLMNKBWkJxSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"New Issue Type" = _t, #"New Subcategory" = _t]),
    MainTableReplaced = Table.FromColumns(List.Transform(List.Zip({Table.ToColumns(MainTable), Table.ToColumns(IssueMapTable)}), each List.Transform(List.Zip(_), each List.Last(List.RemoveNulls(_)))), Value.Type(Table.FirstN(MainTable, 0)))
in
    MainTableReplaced

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

ktbb5757
Regular Visitor

That worked. Thanks so much.

Anonymous
Not applicable

Hi @ktbb5757 ,
You can try the follwing code

let
    MainTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYw7CsNADAWvsqj2KfIjIaRJysXFWmhBWJaCVi58e29M2nkzL2c4OU/kGwxwXb5iG1F6Ms5TwRnGIcPZtApjJKvpoUFOLbr84oYkUpRsbYf4IVyd4/d0K9K4MpZg02O8vzu+9MZ5Yf3zcQc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Prior Issue Type" = _t, #"Prior Subcategory" = _t]),
    IssueMapTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspMSi2qVNJRcs7PzU0tykxOzFGAisXqRCt5BAGlAlKLivPzgBJBqTmJJZn5ecUZmQXFCHm3xJzizDSgVpCcUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"New Issue Type" = _t, #"New Subcategory" = _t]),
    MainWithIndex = Table.AddIndexColumn(MainTable, "Index", 0, 1, Int64.Type),
    IssueMapWithIndex = Table.AddIndexColumn(IssueMapTable, "Index", 0, 1, Int64.Type),
    MergedTables = Table.NestedJoin(MainWithIndex, "Index", IssueMapWithIndex, "Index", "IssueMap", JoinKind.FullOuter),
    ExpandedTable = Table.ExpandTableColumn(MergedTables, "IssueMap", {"New Issue Type", "New Subcategory"}),
    ReplacedTable = Table.AddColumn(ExpandedTable, "Current Issue Type", each if [New Issue Type] = null then [Prior Issue Type] else [New Issue Type]),
    ReplacedTable2 = Table.AddColumn(ReplacedTable, "Current Subcategory", each if [New Subcategory] = null then [Prior Subcategory] else [New Subcategory]),
    FinalTable = Table.SelectColumns(ReplacedTable2, {"Current Issue Type", "Current Subcategory"})
in
    FinalTable

Final output

vheqmsft_0-1726209195896.png

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

lbendlin
Super User
Super User

The most straightforward approach would be to include your reference table in your data model. That would make it simple to swap the old names for the new names, for example via COALESCE.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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